Shapes of numpy arrays

后端 未结 2 927
别那么骄傲
别那么骄傲 2020-12-07 05:10

Been working with numpy for a while now. Just when I think I have arrays figured out, though, it throws me another curve. For instance, I construct the 3D array pltz, and

2条回答
  •  爱一瞬间的悲伤
    2020-12-07 05:48

    You should tell us the lenth of gridset2 and the shape of pltz.

    But I've deduced from the documentation that user2357112 gave us that

    len(gridset2) == 17
    pltz.shape[1] == 160
    

    http://docs.scipy.org/doc/numpy-1.10.0/reference/arrays.indexing.html#combining-advanced-and-basic-indexing

    • The advanced indexes are separated by a slice, ellipsis or newaxis. For example x[arr1, :, arr2].
    • The advanced indexes are all next to each other. For example x[..., arr1, arr2, :] but not x[arr1, :, 1] since 1 is an advanced index in this regard.

    In the first case, the dimensions resulting from the advanced indexing operation come first in the result array, and the subspace dimensions after that. In the second case, the dimensions from the advanced indexing operations are inserted into the result array at the same spot as they were in the initial array

    >>> pltz[10,:,gridset2].shape
    (17, 160)
    

    This is the first case in the quote, a slice in the middle. gridset2 is advanced indexing (e.g. [1,2,3,...]). It is put first; the [10,:] subspace is placed after.

     >>> pltz[10][:,gridset2].shape
     (160, 17)
    

    with pltz[10], the new array (a view) is 2d `(160,N)'. It now puts the size 17 dim last, the 2nd case in the documentation.

提交回复
热议问题