I have an array like:
a = array([[1,2,3],[3,4,5],[4,5,6]])
What’s the most efficient way to slice out a 1×2 array out of this that has only the first two columns of “a”?
i.e.
array([[2,3],[4,5],[5,6]]) in this case.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Two dimensional numpy arrays are indexed using
a[i,j](nota[i][j]), but you can use the same slicing notation with numpy arrays and matrices as you can with ordinary matrices in python (just put them in a single[]):>>> from numpy import array >>> a = array([[1,2,3],[3,4,5],[4,5,6]]) >>> a[:,1:] array([[2, 3], [4, 5], [5, 6]])