[FEATURE REQUEST] support reshape(-1) for ndarrays
Derfies opened this issue · 6 comments
Derfies commented
Super handy to be able to flatten an array to 1 dimension in vanilla numpy, eg:
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr.reshape(-1))
-> [1 2 3 4 5 6]
whereas this raises
TypeError: shape must be a tuple
in ulab.
Using a tuple, ie arr.reshape((-1,)) gives the same issue unfortunately.
Derfies commented
Ah. After a little more perusing I take it that .flatten is the way to go here?
v923z commented
If you want, we could add .reshape(-1)
as an alias for .flatten
. Are they really the same?
Derfies commented
I've used numpy a fair bit but I don't consider myself an authority on the matter. Perhaps leave it as is rather than confused the next boffin who knows the nuance between these two methods!
v923z commented
One element in the tuple can actually be -1: https://numpy.org/doc/stable/reference/generated/numpy.reshape.html
v923z commented
Derfies commented
Thank you!!