如何将向量放入 ND4J 的 INDArray 中?

How to put a vector in INDArray of ND4J?

INDArray a = Nd4j.zeros(2,2);
a.put(1,Nd4j.create(nw float[]{1.0,2.0}));

我试过上面的代码,但它给出了以下错误

java.lang.IllegalArgumentException: Element must be a scalar

我是 ND4J 库的新手。有没有办法直接放一个vector?

 /**
     * Inserts the element at the specified index
     *
     * @param indices the indices to insert into
     * @param element a scalar ndarray
     * @return a scalar ndarray of the element at this index
     */
    INDArray put(int[] indices, INDArray element);

我可以在源代码中看到上面的方法,但为此我需要创建 int 数组,它会消耗内存。

您正在寻找的方法是 putRow,它具有所需的签名:

INDArray putRow(int row, INDArray toPut);

还有 putColumn 对列的工作方式类似。