#Code
import numpy as np
np.random.seed(124)
x_2d = np.random.randint(1,50,(3,4,5))
print("I am getting wrong output => {}".format(x_2d[0][:][1]))
print("This is what I want => {} ".format(x_2d[0,:,1]))
# Code Ended
# Output for above code
I am getting wrong output => [42 1 21 29 15]
This is what I want => [29 1 22 49]
I am new to NumPy so I was just experimenting on numpy array selection techniques. I came to know that we can use square bracket method or comma method. But I encountered a problem. I am trying to extract column index 1 of array 0. But I am getting different outputs when I use both techniques. I have attached code snippets and outputs. Can anyone guide me where did I go wrong ?
Aucun commentaire:
Enregistrer un commentaire