Arraymancer
Arraymancer copied to clipboard
Convert a 1D tensor to 2D tensor
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?
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
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.
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?
Aren't .squeeze
and .unsqueeze
good enough if you want implicit expansion?
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.