0

I have an np array n and the shape is (250,250). after that I converted (final array w)it into (250,250,3) because I need to do some operation on it.

is it possible to convert the shape of w to (250,250)?

thanks in advance. I tried some reshaping operation of Numpy but it does not work!

Numpy reshaping array

Comparing two NumPy arrays for equality, element-wise

Numpy reshaping array

Coder
  • 1,129
  • 10
  • 24
  • 1
    Since you have no code posted it is difficult to understand what you want to do concretely. But you can use w[;,:,0] to get one array of shape (250,250) and w[;,:,1] to get another one and for w[;,:,2] a third one. Does this answer your question? – sehan2 Oct 20 '21 at 10:50

1 Answers1

1

numpy.reshape

Gives a new shape to an array without changing its data.

so this is not right to convert array with shape of (250,250,3) into array with shape of (250,250) as 1st does have 187500 cells and 2nd does have 62500 cells.

You probably should use slicing, consider following example

import numpy as np
arr = np.array([[[0,1],[2,3]],[[4,5],[6,7]]])  # has shape (2,2,2)
arr2 = arr[:,:,0]  # get certain cross-section, check what will happend if you use 1 inplace of 0 and 2 inplace of 0
print("arr2")
print(arr2)
print("arr2.shape",arr2.shape)

output

arr2
[[0 2]
 [4 6]]
arr2.shape (2, 2)
Daweo
  • 31,313
  • 3
  • 12
  • 25