How to take NumPy array to specify rows and columns

Source: Internet
Author: User
This time to bring you how to take NumPy array to specify the row and column, take numpy array to specify the column of attention to what, the following is the actual case, together to see.

The operation on the NumPy array is a bit cumbersome, but there is no way.

For example

A = [[4,5,6], [[7,8,9]]

Take a of 2 3 rows, 1 2 columns

c=[1,2] D =[0,1]

If written as

b = a[c,d] Output: [4 8]

Take the data from the second row, the first column and the third row.

This is not the result we want.

The correct approach is:

b = a[c] First fetch the desired row data B = b[:,d] Print (b) Output: [[4 5] [7 8]]

This is the result we want. This must take two steps to complete.

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

Perfect solution python2.7 cannot use Pip

Python how to read and write TXT file line-wise

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.