Arraymancer icon indicating copy to clipboard operation
Arraymancer copied to clipboard

Convert a 1D tensor to 2D tensor

Open russellb23 opened this issue 4 years ago • 5 comments

Using numpy we can convert 1D array to 2D array as,

a=np.arange(1,10)
a.reshape((3,-1))
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]])

I am a newbie arraymancer user. Is there any way to convert 1D to 2D like the above?

russellb23 avatar May 17 '20 14:05 russellb23

Are your perhapse looking for reshape like used here: https://mratsim.github.io/Arraymancer/tuto.shapeshifting.html ? let a = toSeq(1..9).toTensor().reshape(3,3)

EDIT and links to the doc: https://mratsim.github.io/Arraymancer/shapeshifting.html#reshape%2CTensor%2Cvarargs%5Bint%5D

zetashift avatar May 17 '20 15:05 zetashift

Thanks @zetashift . However with numpy -1 indicates each row to be added as a new axis essentially creating 3 x 3 2D array. With the numpy syntax, it is only enough to specify just number of rows and the columns will be computed automatically with -1 which is newaxis in numpy. I was wondering is there any such trick available which I am not aware of or couldn't find.

russellb23 avatar May 18 '20 03:05 russellb23

No Arraymancer doesn't support that at the moment. It feels a bit like magic. -1 can mean a lot of things in the Python world so I'd rather not re-use -1 especially.

In terms of use-case, is that used often?

mratsim avatar May 20 '20 21:05 mratsim

Aren't .squeeze and .unsqueeze good enough if you want implicit expansion?

DylanModesitt avatar May 25 '20 17:05 DylanModesitt

No Arraymancer doesn't support that at the moment. It feels a bit like magic. -1 can mean a lot of things in the Python world so I'd rather not re-use -1 especially.

In terms of use-case, is that used often?

Yes, using - 1 is really used a lot. For arrays where one of the dimensions is variable, then it would be nice with a fill shape.

zerothi avatar Dec 10 '20 18:12 zerothi