Я новичок в Java.Я хочу создать двумерные Java-массивы на основе сжатых параметров матрицы разреженных столбцов.Например, я могу создать двумерные массивы, используя следующий код в python:
from scipy.sparse import csc_matrix
indices = [0, 2, 2, 0, 1, 2]
indptr = [0,2,3,6]
data = [1, 2, 3, 4, 5, 6]
shape = [3,3]
sp_mat = csc_matrix((data, indices, indptr), shape=shape).todense()
print(sp_mat)
[[1 0 4]
[0 0 5]
[2 3 6]]
Но я не знаю, как этого добиться в JAVA.
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
int[] indices = new int[]{0, 2, 2, 0, 1, 2};
int[] indptr = new int[]{0,2,3,6};
int[] data = new int[]{1, 2, 3, 4, 5, 6};
int[] shape = new int[]{3,3};
// some code to create 2D arrays
}
}
У меня будет массив indices
, indptr
, data
и shape
1D, как показано выше.Я ожидаю, что смогу создать следующие 2D массивы:
int[][] sp_mat = new int[][]{{1,0,4},{0,0,5},{2,3,6}};
Любая помощь будет принята с благодарностью.