NumPy > Select array data

Name
Code
Output
array = numpy.random.randint(10, size=(3, 3))
print ("array \n",array)
print ("elements less than 4 \n", array[array<4])
array 
 [[9 3 1]
 [6 3 2]
 [6 4 4]]
elements less than 2 
 [3 1 3 2]
array = numpy.random.randint(10, size=(3, 3))
print ("array \n",array)
print ("fancy diagonal indexing \n", array[[0,1,2],[0,1,2]])
array 
 [[9 7 0]
 [9 7 3]
 [0 7 2]]
fancy diagonal indexing 
 [9 7 2]
array = numpy.random.randint(10, size=(4))
print ("array \n",array)
print ("slice elements <1,3)", array[1:3])
array 
 [6 9 1 3]
slice elements <1,3) [9 1]
array = numpy.random.randint(5, size=(2, 4))
print ("array \n",array)
print ("second column:", array[:,1])
array 
 [[2 0 0 4]
 [1 0 2 4]]
second column: [0 0]
array = numpy.random.randint(10, size=(3))
print ("array \n",array)
print ("second element \n", array[1])
array 
 [8 6 4]
second element 
 6
array = numpy.random.randint(10, size=(3, 3))
print ("array \n",array)
print ("third row \n", array[2])
array 
 [[2 7 3]
 [0 3 9]
 [1 7 8]]
third row 
 [1 7 8]
array = numpy.random.randint(10, size=(4, 4))
print ("array \n",array)
print ("submatrix \n", array[0:2,0:2])
array 
 [[8 0 3 1]
 [4 8 9 7]
 [0 7 2 6]
 [2 7 4 3]]
submatrix 
 [[8 0]
 [4 8]]
array = numpy.random.randint(10, size=(2,3))
print ("array \n",array)
print ("element at index [0,1]:", array[0,1])
array 
 [[4 9 3]
 [1 3 2]]
element at index [0,1]: 9