This time I will show you how to get the numpyarrayspecify the rows and columns, and what are the notesfor getting the rows and rows of the numpy array. Here is a practical case, let’s take a look.
This operation on the numpy array feels a bit troublesome, but there is nothing we can do.
For example
a = [[1,2,3], [4,5,6], [7,8,9]]
Take 2 3 rows and 1 2 columns of a
c=[1,2] d =[0,1]
If written as
b = a[c,d] output: [4 8]
the data in the first column of the second row and the second column of the third row are taken
This is not the result we want.
The correct approach is:
b = a[c]先取想要的行数据 b = b[:,d] print(b) output: [[4 5] [7 8]]
This is the result we want. You must go through these two steps to complete.
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Perfect solution to python2.7 being unable to use pip
##How to read and write txt files line by line in python
The above is the detailed content of How to get the specified row and column of numpy array. For more information, please follow other related articles on the PHP Chinese website!