INDArray ones = Nd4j.ones(1, 8);
System.out.println(ones.shapeInfoToString());
ones = ones.getRow(0);
System.out.println(ones.shapeInfoToString());
ones = Nd4j.ones(2, 8);
System.out.println(ones.shapeInfoToString());
ones = ones.getRow(0);
System.out.println(ones.shapeInfoToString());
Above code print below lines, why the second line is not the same as the 4th line?
Rank: 2, DataType: FLOAT, Offset: 0, Order: c, Shape: [1,8], Stride: [1,1]
Rank: 2, DataType: FLOAT, Offset: 0, Order: c, Shape: [1,8], Stride: [1,1]
Rank: 2, DataType: FLOAT, Offset: 0, Order: c, Shape: [2,8], Stride: [8,1]
Rank: 1, DataType: FLOAT, Offset: 0, Order: c, Shape: [8], Stride: [1]
@SidneyLann that’s likely due to it just returning the result as is. It’s already a vector. Nothing is really executed unless there’s a row to actually get. Feel free to file an issue and we can do a proper reshape call there.
The rank in the second line should be 1 but not 2, right?
In my app, indArray.getRow(0); return the whole INDArray when the first shape is 1, and return correct Row when the first shape is bigger then 1.
That means I can get the first row when an INDArray has multiple rows, but can’t get the first row when an INDArray has ONLY 1 row.
@SidneyLann why would you need to do that though? A 1 x 8 is already a row vector and by definition the result.
We generally treat 1 x 8 and 8 as the same.
If you want just reshape it for now. I already mentioned you could file an issue if you see it as a bug and I ccan take a look.
for (int j = 0; j < crawlIdsSize; j++) {
tmp = outArray.getRow(j);
…
The behavior must be the same, must always get [8] but not [1,8] when crawlIdsSize is 1.
@SidneyLann just detect when it’s length 1 for now and file an issue then. I’m not going to fix this on the spot from a forum post. I’ll do it with a quick reproducer and a corresponding issue I can reference on the tracker. I already mentioned the likely issue and a workaround a few times now.
I’m not going to do much more here.
INDArray ones = Nd4j.ones(1, 8);
System.out.println(ones.shapeInfoToString());
ones = ones.get(point(0),all());
System.out.println(ones.shapeInfoToString());
ones = Nd4j.ones(2, 8);
System.out.println(ones.shapeInfoToString());
ones = ones.getRow(0);
System.out.println(ones.shapeInfoToString());
Rank: 2, DataType: FLOAT, Offset: 0, Order: c, Shape: [1,8], Stride: [1,1]
Rank: 1, DataType: FLOAT, Offset: 0, Order: f, Shape: [8], Stride: [1]
Rank: 2, DataType: FLOAT, Offset: 0, Order: c, Shape: [2,8], Stride: [8,1]
Rank: 1, DataType: FLOAT, Offset: 0, Order: c, Shape: [8], Stride: [1]
Why the order of the second line is f, how to get c by .get(point(0),all())?
@SidneyLann c vs f shouldn’t affect you here either. I would consider any of that as a distraction. As long as the results are correct it doesn’t matter.
C vs f mainly affects matrix multiplies and a few other specific ops.
C is the default ordering though. Why it returns certain orders I’d have to take a closer look at the indexing implementation again.
Ok. call tmp.setOrder(‘c’) if necessary.