python - numpy array slicing unxpected results -


i don't understand behavior below. numpy arrays can accessed through indexing, [:,1] should equivalent [:][1], or thought. explain why not case?

>>> = np.array([[1, 2, 3], [4, 5, 6]])   >>> a[:,1]   array([2, 5])   >>> a[:][1]   array([4, 5, 6]) 

thanks!

those 2 forms of indexing not same. should use [i, j] , not [i][j]. both work, first faster (see this question).

using 2 indices [i][j] 2 operations. first index , second on result of first operation. [:] returns entire array, first 1 equivalent array[1]. since 1 index passed, assumed refer first dimension (rows), means "get row 1". using 1 compound index [i, j] single operation uses both indexing conditions @ once, array[:, 1] returns "all rows, column 1".


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -