I've started using the Deep Java Library together with its underlying array manipulation package: ndarray.
The question is very simple. I want to modify the i
-th element of an existing NDArray, however I cannot do that. How can I set the i
-th element to a specific value?
The documentation mentions many set
methods.
Here's a minimum reproducible example of what I've tried:
var manager = NDManager.newBaseManager();
var y = manager.create(new float[] {1, 2, 3, 4, 5});
System.out.println("y before modification: " + y);
y.set(new float[] {1, 100, 3, 4, 5});
System.out.println("y after setting the entire array: " + y);
// the following throws: "java.lang.UnsupportedOperationException: Tensor cannot be modified after creation"
y.set(new NDIndex("1"), 1000f);
System.out.println("y after setting the 1st element to 1000: " + y);
This the error thrown:
java.lang.UnsupportedOperationException: Tensor cannot be modified after creation