How to get the specified row and column of numpy array

php中世界最好的语言
Release: 2018-04-09 10:55:30
Original
9685 people have browsed it

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]]
Copy after login

Take 2 3 rows and 1 2 columns of a

c=[1,2] 
d =[0,1]
Copy after login

If written as

b = a[c,d] 
output: 
[4 8]
Copy after login

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]]
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!