是'的MATLAB函数;重塑';在任何Java库中都可用吗?
我试图使用Java中MATLAB中可用的重塑函数的功能。Java中有重塑的实现吗?我在网站上发现了这个(稍作修改)是'的MATLAB函数;重塑';在任何Java库中都可用吗?,java,matlab,reshape,Java,Matlab,Reshape,我试图使用Java中MATLAB中可用的重塑函数的功能。Java中有重塑的实现吗?我在网站上发现了这个(稍作修改) 有点晚了,但对未来的访客来说。 有支持这种操作的 这是一个用Java处理数据的库。它的部分灵感来自NumPy,旨在提供类似的功能 它确实支持数据集上的重塑功能。 你可以浏览一下网页 (以上示例中的代码) 非常感谢Glowcoder!你能给我建议一些重塑从一个维度到另一个维度的想法吗。我希望将一维(a[50400])数组转换为7维数组(b[2][12][4][5][5][7][3])
有点晚了,但对未来的访客来说。 有支持这种操作的 这是一个用Java处理数据的库。它的部分灵感来自NumPy,旨在提供类似的功能 它确实支持
数据集
上的重塑
功能。
你可以浏览一下网页
(以上示例中的代码)
非常感谢Glowcoder!你能给我建议一些重塑从一个维度到另一个维度的想法吗。我希望将一维(a[50400])数组转换为7维数组(b[2][12][4][5][5][7][3])。另一种情况是将2d数组(c[1260][12])转换为3d数组(d[60][21][12])
public class Test {
public static void main(String[] args) {
double[][] ori = new double[][] { {1,2,3}, {4,5,6}, {7,8,9}, {10,11,12} };
double[][] res = reshape(ori,2,6);
for(int i = 0;i<ori.length;i++){
for(int j = 0;j<ori[0].length;j++){
System.out.print(ori[i][j]+" ");
}
System.out.println("");
}
System.out.println("");
for(int i = 0;i<res.length;i++){
for(int j = 0;j<res[0].length;j++){
System.out.print(res[i][j]+" ");
}
System.out.println("");
}
}
public static double[][] reshape(double[][] A, int m, int n) {
int origM = A.length;
int origN = A[0].length;
if(origM*origN != m*n){
throw new IllegalArgumentException("New matrix must be of same area as matix A");
}
double[][] B = new double[m][n];
double[] A1D = new double[A.length * A[0].length];
int index = 0;
for(int i = 0;i<A.length;i++){
for(int j = 0;j<A[0].length;j++){
A1D[index++] = A[i][j];
}
}
index = 0;
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++){
B[j][i] = A1D[index++];
}
}
return B;
}
}
1.0 2.0 3.0
4.0 5.0 6.0
7.0 8.0 9.0
10.0 11.0 12.0
1.0 3.0 5.0 7.0 9.0 11.0
2.0 4.0 6.0 8.0 10.0 12.0
Dataset another = DatasetFactory
.createFromObject(new double[] { 1, 1, 2, 3, 5, 8, 13, 21, 34 })
.reshape(3, 3);