2
votes

I have a numpy ndarray of 3D coordinates in the following form..

array([[  0.,   0.,  60.],
       [  0.,  40.,  60.],
       [  0.,  40.,   0.],
       ..., 
       [  6.,   0.,   2.],
       [  4.,   0.,   2.],
       [  2.,   0.,   2.]])

I'm trying to reshape it so that rather than a 1D vector of coordinates I get a 2D grid of coordinates.

The original array is of length 1302 which should allow me to reshape into a 21x62 arrangement.

I tried coords_reshaped = np.ndarray.reshape(coords, (21,62)) but this spat out the error,

ValueError: total size of new array must be unchanged

So what am I missing here?

1
"I'm trying to reshape it so that rather than a 1D vector of coordinates I get a 2D grid of coordinates." - you already have a 2D grid. - user2357112 supports Monica
To clarify, I have a 1D vector of 3D coordinates - DrBwts
@user2357112 How? It's 1 row and n columns. - Jossie Calderon
@DrBwts You should at least express what you want your output to be. Do you want 2x3 elements? - Jossie Calderon
@JossieCalderon I mentioned it in the OP, 21x62 - DrBwts

1 Answers

3
votes
coords_reshaped = coords.reshape((21, 62, 3))