I'm trying to get the first 784 elements of a numpy array. Is there a way to this? I tried doing array = array[:783]
, but that doesn't seem to work. I also tried converting it to a list and then back to a numpy array like this
python_list = numpy_array.tolist()
cut_numpy_array = np.array(python_list[:783])
but that also doesn't seem to work. Is there a way to do this?
CodePudding user response:
If you have more than one-dimensional numpy array, slicing won't work that way. You can try other ways.
Use np.ravel()
array = np.ravel(array)[0:783]
CodePudding user response:
If you are working with 2D array then you have to give starting and ending point of rows and starting and ending point of columns. value = image[starting:ending, starting:ending]