Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

Suppose I have:

test = numpy.array([[1, 2], [3, 4], [5, 6]])

test[i] gets me ith line of the array (eg [1, 2]). How can I access the ith column? (eg [1, 3, 5]). Also, would this be an expensive operation?

1 Answer

0 votes
by (106k points)

Python has a wonderful method that is called as slicing this can be used to access the ith column of a NumPy multidimensional array we will use this as follows:-

import numpy as np

test = np.array([[1, 2], [3, 4], [5, 6]])

print(test[:,0])

image

Related questions

0 votes
4 answers
0 votes
2 answers
0 votes
1 answer
asked Jul 17, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...