How to use Python to get some rows and columns of numpy array
This article mainly explains "how to use Python to get a few rows and columns of numpy array". The explanation in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian and go deep into it slowly to study and learn "how to use Python to get a few rows and columns of numpy array"!
Foreword:
What I'm going to bring you today is Python's method of taking a few rows and columns of numpy arrays.
Direct analysis, such as the original matrix as follows (1):
(1)
The matrix we want to intercept (take one of the three rows and three or four columns of data to form a matrix) is as follows (2):
(2)
Error analysis:
Take 1 3 rows, 3 4 columns of C, define Z = [0,2] #define rows d = [2,3] #define columns #code C_zd = C[z,d]
The result is:
The analysis of the results takes the data in the first row, the third column and the fourth column of the third row, which is not the result we want.
Correct analysis:
C_A = c[[0,2]] #Take out the desired row data C_A = C_A[:,[2,3]] #Take out the required column data print(C_A) #Output the final result
The results are:
The result is what we solve for, and it takes two steps to complete.
Thank you for reading, the above is "how to use Python to get a few rows of numpy array a few columns" content, after the study of this article, I believe that everyone on how to use Python to get a few rows of numpy array a few columns this problem has a deeper understanding, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!