Say I have a 2D array like the one below:
array([3, 6, 7
1,-1, 3])
I would like to get in 3 separate arrays the x
, y
and value
of the array . In other words:
x = [0, 1, 0, 1, 0, 1]
y = [0, 0, 1, 1, 2, 2]
values = [3, 1, 6, -1, 7, 3]
How can I do this?
For reference, this is what MATLAB calls linear indexing.
How about something like:
x, y = np.indices(array.shape)
x = x.ravel(order='F')
y = y.ravel(order='F')
values = array.ravel(order='F')
def xyval(A):
x, y = np.indices(A.shape)
return x.ravel(), y.ravel(), A.ravel()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With