# Shape is not the same for the first row

**URL:** <https://community.konduit.ai/t/shape-is-not-the-same-for-the-first-row/1897>\
**Category:** ND4J\
**Created:** [June 8, 2022, 7:32am UTC](https://community.konduit.ai/t/shape-is-not-the-same-for-the-first-row/1897 "2022-06-08T07:32:11Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![SidneyLann](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/sidneylann/32/367_2.png) [@SidneyLann](https://community.konduit.ai/u/SidneyLann)\
**Post date:** [June 8, 2022, 7:32am UTC](https://community.konduit.ai/t/shape-is-not-the-same-for-the-first-row/1897/1 "2022-06-08T07:32:11Z")

</div>

```
 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]

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [June 8, 2022, 10:51am UTC](https://community.konduit.ai/t/shape-is-not-the-same-for-the-first-row/1897/2 "2022-06-08T10:51:09Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![SidneyLann](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/sidneylann/32/367_2.png) [@SidneyLann](https://community.konduit.ai/u/SidneyLann)\
**Post date:** [June 8, 2022, 11:32am UTC](https://community.konduit.ai/t/shape-is-not-the-same-for-the-first-row/1897/3 "2022-06-08T11:32:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [June 8, 2022, 11:42am UTC](https://community.konduit.ai/t/shape-is-not-the-same-for-the-first-row/1897/4 "2022-06-08T11:42:27Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![SidneyLann](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/sidneylann/32/367_2.png) [@SidneyLann](https://community.konduit.ai/u/SidneyLann)\
**Post date:** [June 8, 2022, 11:50am UTC](https://community.konduit.ai/t/shape-is-not-the-same-for-the-first-row/1897/5 "2022-06-08T11:50:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [June 8, 2022, 11:52am UTC](https://community.konduit.ai/t/shape-is-not-the-same-for-the-first-row/1897/6 "2022-06-08T11:52:00Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![SidneyLann](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/sidneylann/32/367_2.png) [@SidneyLann](https://community.konduit.ai/u/SidneyLann)\
**Post date:** [June 8, 2022, 11:55am UTC](https://community.konduit.ai/t/shape-is-not-the-same-for-the-first-row/1897/7 "2022-06-08T11:55:44Z")

</div>

Ok, will fire an issue.

---

<div class="post-metadata">

**Author:** ![SidneyLann](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/sidneylann/32/367_2.png) [@SidneyLann](https://community.konduit.ai/u/SidneyLann)\
**Post date:** [June 8, 2022, 11:58am UTC](https://community.konduit.ai/t/shape-is-not-the-same-for-the-first-row/1897/8 "2022-06-08T11:58:52Z")

</div>

```
  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())?

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [June 8, 2022, 12:08pm UTC](https://community.konduit.ai/t/shape-is-not-the-same-for-the-first-row/1897/9 "2022-06-08T12:08:12Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![SidneyLann](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/sidneylann/32/367_2.png) [@SidneyLann](https://community.konduit.ai/u/SidneyLann)\
**Post date:** [June 8, 2022, 12:17pm UTC](https://community.konduit.ai/t/shape-is-not-the-same-for-the-first-row/1897/10 "2022-06-08T12:17:20Z")

</div>

Ok. call tmp.setOrder(‘c’) if necessary.
