Python array indexed with list but array dimensions are permuted The Next CEO of Stack OverflowHow do I check if a list is empty?Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonDoes Python have a ternary conditional operator?Accessing the index in 'for' loops?How to make a flat list out of list of lists?How do I list all files of a directory?Does Python have a string 'contains' substring method?

What was Carter Burke's job for "the company" in Aliens?

Expressing the idea of having a very busy time

What is the difference between "hamstring tendon" and "common hamstring tendon"?

What does "shotgun unity" refer to here in this sentence?

Pulling the principal components out of a DimensionReducerFunction?

Graph of the history of databases

Strange use of "whether ... than ..." in official text

What connection does MS Office have to Netscape Navigator?

Film where the government was corrupt with aliens, people sent to kill aliens are given rigged visors not showing the right aliens

Reference request: Grassmannian and Plucker coordinates in type B, C, D

Why is information "lost" when it got into a black hole?

What would be the main consequences for a country leaving the WTO?

Won the lottery - how do I keep the money?

what's the use of '% to gdp' type of variables?

Is French Guiana a (hard) EU border?

Is there a reasonable and studied concept of reduction between regular languages?

Is a distribution that is normal, but highly skewed, considered Gaussian?

Can I calculate next year's exemptions based on this year's refund/amount owed?

Getting Stale Gas Out of a Gas Tank w/out Dropping the Tank

Does higher Oxidation/ reduction potential translate to higher energy storage in battery?

TikZ: How to fill area with a special pattern?

How to find image of a complex function with given constraints?

Reshaping json / reparing json inside shell script (remove trailing comma)

Physiological effects of huge anime eyes



Python array indexed with list but array dimensions are permuted



The Next CEO of Stack OverflowHow do I check if a list is empty?Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonDoes Python have a ternary conditional operator?Accessing the index in 'for' loops?How to make a flat list out of list of lists?How do I list all files of a directory?Does Python have a string 'contains' substring method?










5















I try to index an array (has five dimensions) using a list. However, under certain situation, the array is permuted.



Say, a has the shape of (3,4,5,6,7), i.e.,



>>> a = np.zeros((3,4,5,6,7))
>>> a.shape
(3, 4, 5, 6, 7)


Using a list to index this array on the third dimension, it looks normal:



>>> a[:,:,[0,3],:,:].shape
(3, 4, 2, 6, 7)


However, if the array were indexed under the following situation, the third dimension is permuted to the leftmost:



>>> a[0,:,[0,1],:,:].shape
(2, 4, 6, 7)


Can anyone shed some light on it?










share|improve this question




























    5















    I try to index an array (has five dimensions) using a list. However, under certain situation, the array is permuted.



    Say, a has the shape of (3,4,5,6,7), i.e.,



    >>> a = np.zeros((3,4,5,6,7))
    >>> a.shape
    (3, 4, 5, 6, 7)


    Using a list to index this array on the third dimension, it looks normal:



    >>> a[:,:,[0,3],:,:].shape
    (3, 4, 2, 6, 7)


    However, if the array were indexed under the following situation, the third dimension is permuted to the leftmost:



    >>> a[0,:,[0,1],:,:].shape
    (2, 4, 6, 7)


    Can anyone shed some light on it?










    share|improve this question


























      5












      5








      5


      1






      I try to index an array (has five dimensions) using a list. However, under certain situation, the array is permuted.



      Say, a has the shape of (3,4,5,6,7), i.e.,



      >>> a = np.zeros((3,4,5,6,7))
      >>> a.shape
      (3, 4, 5, 6, 7)


      Using a list to index this array on the third dimension, it looks normal:



      >>> a[:,:,[0,3],:,:].shape
      (3, 4, 2, 6, 7)


      However, if the array were indexed under the following situation, the third dimension is permuted to the leftmost:



      >>> a[0,:,[0,1],:,:].shape
      (2, 4, 6, 7)


      Can anyone shed some light on it?










      share|improve this question
















      I try to index an array (has five dimensions) using a list. However, under certain situation, the array is permuted.



      Say, a has the shape of (3,4,5,6,7), i.e.,



      >>> a = np.zeros((3,4,5,6,7))
      >>> a.shape
      (3, 4, 5, 6, 7)


      Using a list to index this array on the third dimension, it looks normal:



      >>> a[:,:,[0,3],:,:].shape
      (3, 4, 2, 6, 7)


      However, if the array were indexed under the following situation, the third dimension is permuted to the leftmost:



      >>> a[0,:,[0,1],:,:].shape
      (2, 4, 6, 7)


      Can anyone shed some light on it?







      python numpy numpy-ndarray numpy-broadcasting






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 17:41









      Justice_Lords

      711111




      711111










      asked Mar 4 at 15:45









      Liang GuoLiang Guo

      262




      262






















          2 Answers
          2






          active

          oldest

          votes


















          1














          Basic Slicing:-



          Basic Slicing occurs when a slice object is used.Usually a slice object is constructed as array[(start:stop:step)]. Ellipsis and newaxis also comes under this.



          Example:- 1D array



          >>x=np.arange(10) 
          >>x[2:10:3]
          array([2, 5, 8])


          Example:- 2D array



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


          Example:- 3D array



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


          In the above example the number of slices(obj) given is less than that of the total number of dimension of the array. If the number of objects in the selection tuple is less than N, then it is assumed for any subsequent dimensions.



          Advanced Slicing:-



          Advanced indexing is triggered when the selection object, obj,



          1. is a non-tuple sequence object,

          2. an ndarray (of data type integer or bool),

          3. a tuple with at least one sequence object or ndarray (of data type integer or bool).

          There are two types of advanced indexing: Integer and Boolean.



          Integer Indexing:-



          Integer array indexing allows selection of arbitrary items in the array based on their N-dimensional index. Each integer array represents a number of indexes into that dimension.



          When the index consists of as many integer arrays as the array being indexed has dimensions, the indexing is straight forward, but different from slicing.



          Example:-



          >>a = np.array([[1,2,3],[4,5,6],[7,8,9]])
          >>a[[0,1,2],[0,1,1]]
          array([1, 5, 8])


          Array Visualization



          The above example prints:
          a[0,0],a[1,0],a[2,1]



          Remember:- So Integer Indexing maps between two indexes.



          Now to your question:-



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


          First Case:-



          This is of the form x[arr1,:,arr2].
          arr1 and arr2 are advanced indexes.We consider 0 also to be an advanced index.



          If the advanced indexes are separated by a slice, Ellipsis or newaxis then the dimensions resulting from the advanced indexing operation come first in the result array, and the subspace dimensions after that.



          This essentially means that the dimension of [0,1] comes first in the array. I am leaving off 0 as it has no dimension.



          >>>a[0,:,[0,1]].shape
          (2,4)


          Second case:-



          This is of the form x[:,:,arr1]. Here only arr1 is advanced index.



          If the advanced indexes are all next to each other then the dimensions from the advanced indexing operations are inserted into the result array at the same spot as they were in the initial array.



          This essentially means that the dimension of [0,1] comes at its respective position specified in the index of the array.



          >>>a[0:1,:,[0,1]].shape
          (1,4,2)


          [0,1] has shape(2,) and since it occurs at third index it is inserted into 3rd index of the result array.



          Any suggestions and improvements are Welcome.



          Reference:-



          1. Numpy_Docs





          share|improve this answer

























          • thanks for the answer and the reference.

            – Liang Guo
            Mar 15 at 22:42


















          0














          Thanks @Hari_Sheldon for the reply. Now, I've seen what print has done to the array a, but I still do not understand why Python takes those columns specified by a list and puts them as rows at the leftmost position. Is there any reference out there to explain the reason?



          And, under some situations, this dimension permutation does not occur, i.e.:



          >>> a[0:1,:,[0,3]].shape
          (1, 4, 2)


          As you can see, instead of permuting it into (2, 4), the dimensional order remains!






          share|improve this answer























          • You have answered wherein you have to comment. You can understand if you try out the difference between a[0] and a[0:1] one returns a shape () and the other returns a shape (1,) for 1D list

            – Justice_Lords
            Mar 6 at 8:07











          • Yes, I understand the rule of retaining a degenerated dimension. However, I donot understand why retaining a degenerated dimension prevents the array from permutation. In another word, why not a[0:1,0,[0,3]] returns a shape of (2,1,4)?

            – Liang Guo
            Mar 7 at 9:41











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54986672%2fpython-array-indexed-with-list-but-array-dimensions-are-permuted%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Basic Slicing:-



          Basic Slicing occurs when a slice object is used.Usually a slice object is constructed as array[(start:stop:step)]. Ellipsis and newaxis also comes under this.



          Example:- 1D array



          >>x=np.arange(10) 
          >>x[2:10:3]
          array([2, 5, 8])


          Example:- 2D array



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


          Example:- 3D array



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


          In the above example the number of slices(obj) given is less than that of the total number of dimension of the array. If the number of objects in the selection tuple is less than N, then it is assumed for any subsequent dimensions.



          Advanced Slicing:-



          Advanced indexing is triggered when the selection object, obj,



          1. is a non-tuple sequence object,

          2. an ndarray (of data type integer or bool),

          3. a tuple with at least one sequence object or ndarray (of data type integer or bool).

          There are two types of advanced indexing: Integer and Boolean.



          Integer Indexing:-



          Integer array indexing allows selection of arbitrary items in the array based on their N-dimensional index. Each integer array represents a number of indexes into that dimension.



          When the index consists of as many integer arrays as the array being indexed has dimensions, the indexing is straight forward, but different from slicing.



          Example:-



          >>a = np.array([[1,2,3],[4,5,6],[7,8,9]])
          >>a[[0,1,2],[0,1,1]]
          array([1, 5, 8])


          Array Visualization



          The above example prints:
          a[0,0],a[1,0],a[2,1]



          Remember:- So Integer Indexing maps between two indexes.



          Now to your question:-



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


          First Case:-



          This is of the form x[arr1,:,arr2].
          arr1 and arr2 are advanced indexes.We consider 0 also to be an advanced index.



          If the advanced indexes are separated by a slice, Ellipsis or newaxis then the dimensions resulting from the advanced indexing operation come first in the result array, and the subspace dimensions after that.



          This essentially means that the dimension of [0,1] comes first in the array. I am leaving off 0 as it has no dimension.



          >>>a[0,:,[0,1]].shape
          (2,4)


          Second case:-



          This is of the form x[:,:,arr1]. Here only arr1 is advanced index.



          If the advanced indexes are all next to each other then the dimensions from the advanced indexing operations are inserted into the result array at the same spot as they were in the initial array.



          This essentially means that the dimension of [0,1] comes at its respective position specified in the index of the array.



          >>>a[0:1,:,[0,1]].shape
          (1,4,2)


          [0,1] has shape(2,) and since it occurs at third index it is inserted into 3rd index of the result array.



          Any suggestions and improvements are Welcome.



          Reference:-



          1. Numpy_Docs





          share|improve this answer

























          • thanks for the answer and the reference.

            – Liang Guo
            Mar 15 at 22:42















          1














          Basic Slicing:-



          Basic Slicing occurs when a slice object is used.Usually a slice object is constructed as array[(start:stop:step)]. Ellipsis and newaxis also comes under this.



          Example:- 1D array



          >>x=np.arange(10) 
          >>x[2:10:3]
          array([2, 5, 8])


          Example:- 2D array



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


          Example:- 3D array



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


          In the above example the number of slices(obj) given is less than that of the total number of dimension of the array. If the number of objects in the selection tuple is less than N, then it is assumed for any subsequent dimensions.



          Advanced Slicing:-



          Advanced indexing is triggered when the selection object, obj,



          1. is a non-tuple sequence object,

          2. an ndarray (of data type integer or bool),

          3. a tuple with at least one sequence object or ndarray (of data type integer or bool).

          There are two types of advanced indexing: Integer and Boolean.



          Integer Indexing:-



          Integer array indexing allows selection of arbitrary items in the array based on their N-dimensional index. Each integer array represents a number of indexes into that dimension.



          When the index consists of as many integer arrays as the array being indexed has dimensions, the indexing is straight forward, but different from slicing.



          Example:-



          >>a = np.array([[1,2,3],[4,5,6],[7,8,9]])
          >>a[[0,1,2],[0,1,1]]
          array([1, 5, 8])


          Array Visualization



          The above example prints:
          a[0,0],a[1,0],a[2,1]



          Remember:- So Integer Indexing maps between two indexes.



          Now to your question:-



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


          First Case:-



          This is of the form x[arr1,:,arr2].
          arr1 and arr2 are advanced indexes.We consider 0 also to be an advanced index.



          If the advanced indexes are separated by a slice, Ellipsis or newaxis then the dimensions resulting from the advanced indexing operation come first in the result array, and the subspace dimensions after that.



          This essentially means that the dimension of [0,1] comes first in the array. I am leaving off 0 as it has no dimension.



          >>>a[0,:,[0,1]].shape
          (2,4)


          Second case:-



          This is of the form x[:,:,arr1]. Here only arr1 is advanced index.



          If the advanced indexes are all next to each other then the dimensions from the advanced indexing operations are inserted into the result array at the same spot as they were in the initial array.



          This essentially means that the dimension of [0,1] comes at its respective position specified in the index of the array.



          >>>a[0:1,:,[0,1]].shape
          (1,4,2)


          [0,1] has shape(2,) and since it occurs at third index it is inserted into 3rd index of the result array.



          Any suggestions and improvements are Welcome.



          Reference:-



          1. Numpy_Docs





          share|improve this answer

























          • thanks for the answer and the reference.

            – Liang Guo
            Mar 15 at 22:42













          1












          1








          1







          Basic Slicing:-



          Basic Slicing occurs when a slice object is used.Usually a slice object is constructed as array[(start:stop:step)]. Ellipsis and newaxis also comes under this.



          Example:- 1D array



          >>x=np.arange(10) 
          >>x[2:10:3]
          array([2, 5, 8])


          Example:- 2D array



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


          Example:- 3D array



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


          In the above example the number of slices(obj) given is less than that of the total number of dimension of the array. If the number of objects in the selection tuple is less than N, then it is assumed for any subsequent dimensions.



          Advanced Slicing:-



          Advanced indexing is triggered when the selection object, obj,



          1. is a non-tuple sequence object,

          2. an ndarray (of data type integer or bool),

          3. a tuple with at least one sequence object or ndarray (of data type integer or bool).

          There are two types of advanced indexing: Integer and Boolean.



          Integer Indexing:-



          Integer array indexing allows selection of arbitrary items in the array based on their N-dimensional index. Each integer array represents a number of indexes into that dimension.



          When the index consists of as many integer arrays as the array being indexed has dimensions, the indexing is straight forward, but different from slicing.



          Example:-



          >>a = np.array([[1,2,3],[4,5,6],[7,8,9]])
          >>a[[0,1,2],[0,1,1]]
          array([1, 5, 8])


          Array Visualization



          The above example prints:
          a[0,0],a[1,0],a[2,1]



          Remember:- So Integer Indexing maps between two indexes.



          Now to your question:-



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


          First Case:-



          This is of the form x[arr1,:,arr2].
          arr1 and arr2 are advanced indexes.We consider 0 also to be an advanced index.



          If the advanced indexes are separated by a slice, Ellipsis or newaxis then the dimensions resulting from the advanced indexing operation come first in the result array, and the subspace dimensions after that.



          This essentially means that the dimension of [0,1] comes first in the array. I am leaving off 0 as it has no dimension.



          >>>a[0,:,[0,1]].shape
          (2,4)


          Second case:-



          This is of the form x[:,:,arr1]. Here only arr1 is advanced index.



          If the advanced indexes are all next to each other then the dimensions from the advanced indexing operations are inserted into the result array at the same spot as they were in the initial array.



          This essentially means that the dimension of [0,1] comes at its respective position specified in the index of the array.



          >>>a[0:1,:,[0,1]].shape
          (1,4,2)


          [0,1] has shape(2,) and since it occurs at third index it is inserted into 3rd index of the result array.



          Any suggestions and improvements are Welcome.



          Reference:-



          1. Numpy_Docs





          share|improve this answer















          Basic Slicing:-



          Basic Slicing occurs when a slice object is used.Usually a slice object is constructed as array[(start:stop:step)]. Ellipsis and newaxis also comes under this.



          Example:- 1D array



          >>x=np.arange(10) 
          >>x[2:10:3]
          array([2, 5, 8])


          Example:- 2D array



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


          Example:- 3D array



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


          In the above example the number of slices(obj) given is less than that of the total number of dimension of the array. If the number of objects in the selection tuple is less than N, then it is assumed for any subsequent dimensions.



          Advanced Slicing:-



          Advanced indexing is triggered when the selection object, obj,



          1. is a non-tuple sequence object,

          2. an ndarray (of data type integer or bool),

          3. a tuple with at least one sequence object or ndarray (of data type integer or bool).

          There are two types of advanced indexing: Integer and Boolean.



          Integer Indexing:-



          Integer array indexing allows selection of arbitrary items in the array based on their N-dimensional index. Each integer array represents a number of indexes into that dimension.



          When the index consists of as many integer arrays as the array being indexed has dimensions, the indexing is straight forward, but different from slicing.



          Example:-



          >>a = np.array([[1,2,3],[4,5,6],[7,8,9]])
          >>a[[0,1,2],[0,1,1]]
          array([1, 5, 8])


          Array Visualization



          The above example prints:
          a[0,0],a[1,0],a[2,1]



          Remember:- So Integer Indexing maps between two indexes.



          Now to your question:-



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


          First Case:-



          This is of the form x[arr1,:,arr2].
          arr1 and arr2 are advanced indexes.We consider 0 also to be an advanced index.



          If the advanced indexes are separated by a slice, Ellipsis or newaxis then the dimensions resulting from the advanced indexing operation come first in the result array, and the subspace dimensions after that.



          This essentially means that the dimension of [0,1] comes first in the array. I am leaving off 0 as it has no dimension.



          >>>a[0,:,[0,1]].shape
          (2,4)


          Second case:-



          This is of the form x[:,:,arr1]. Here only arr1 is advanced index.



          If the advanced indexes are all next to each other then the dimensions from the advanced indexing operations are inserted into the result array at the same spot as they were in the initial array.



          This essentially means that the dimension of [0,1] comes at its respective position specified in the index of the array.



          >>>a[0:1,:,[0,1]].shape
          (1,4,2)


          [0,1] has shape(2,) and since it occurs at third index it is inserted into 3rd index of the result array.



          Any suggestions and improvements are Welcome.



          Reference:-



          1. Numpy_Docs






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 8 at 12:35

























          answered Mar 4 at 16:30









          Justice_LordsJustice_Lords

          711111




          711111












          • thanks for the answer and the reference.

            – Liang Guo
            Mar 15 at 22:42

















          • thanks for the answer and the reference.

            – Liang Guo
            Mar 15 at 22:42
















          thanks for the answer and the reference.

          – Liang Guo
          Mar 15 at 22:42





          thanks for the answer and the reference.

          – Liang Guo
          Mar 15 at 22:42













          0














          Thanks @Hari_Sheldon for the reply. Now, I've seen what print has done to the array a, but I still do not understand why Python takes those columns specified by a list and puts them as rows at the leftmost position. Is there any reference out there to explain the reason?



          And, under some situations, this dimension permutation does not occur, i.e.:



          >>> a[0:1,:,[0,3]].shape
          (1, 4, 2)


          As you can see, instead of permuting it into (2, 4), the dimensional order remains!






          share|improve this answer























          • You have answered wherein you have to comment. You can understand if you try out the difference between a[0] and a[0:1] one returns a shape () and the other returns a shape (1,) for 1D list

            – Justice_Lords
            Mar 6 at 8:07











          • Yes, I understand the rule of retaining a degenerated dimension. However, I donot understand why retaining a degenerated dimension prevents the array from permutation. In another word, why not a[0:1,0,[0,3]] returns a shape of (2,1,4)?

            – Liang Guo
            Mar 7 at 9:41















          0














          Thanks @Hari_Sheldon for the reply. Now, I've seen what print has done to the array a, but I still do not understand why Python takes those columns specified by a list and puts them as rows at the leftmost position. Is there any reference out there to explain the reason?



          And, under some situations, this dimension permutation does not occur, i.e.:



          >>> a[0:1,:,[0,3]].shape
          (1, 4, 2)


          As you can see, instead of permuting it into (2, 4), the dimensional order remains!






          share|improve this answer























          • You have answered wherein you have to comment. You can understand if you try out the difference between a[0] and a[0:1] one returns a shape () and the other returns a shape (1,) for 1D list

            – Justice_Lords
            Mar 6 at 8:07











          • Yes, I understand the rule of retaining a degenerated dimension. However, I donot understand why retaining a degenerated dimension prevents the array from permutation. In another word, why not a[0:1,0,[0,3]] returns a shape of (2,1,4)?

            – Liang Guo
            Mar 7 at 9:41













          0












          0








          0







          Thanks @Hari_Sheldon for the reply. Now, I've seen what print has done to the array a, but I still do not understand why Python takes those columns specified by a list and puts them as rows at the leftmost position. Is there any reference out there to explain the reason?



          And, under some situations, this dimension permutation does not occur, i.e.:



          >>> a[0:1,:,[0,3]].shape
          (1, 4, 2)


          As you can see, instead of permuting it into (2, 4), the dimensional order remains!






          share|improve this answer













          Thanks @Hari_Sheldon for the reply. Now, I've seen what print has done to the array a, but I still do not understand why Python takes those columns specified by a list and puts them as rows at the leftmost position. Is there any reference out there to explain the reason?



          And, under some situations, this dimension permutation does not occur, i.e.:



          >>> a[0:1,:,[0,3]].shape
          (1, 4, 2)


          As you can see, instead of permuting it into (2, 4), the dimensional order remains!







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 5 at 10:12









          Liang GuoLiang Guo

          262




          262












          • You have answered wherein you have to comment. You can understand if you try out the difference between a[0] and a[0:1] one returns a shape () and the other returns a shape (1,) for 1D list

            – Justice_Lords
            Mar 6 at 8:07











          • Yes, I understand the rule of retaining a degenerated dimension. However, I donot understand why retaining a degenerated dimension prevents the array from permutation. In another word, why not a[0:1,0,[0,3]] returns a shape of (2,1,4)?

            – Liang Guo
            Mar 7 at 9:41

















          • You have answered wherein you have to comment. You can understand if you try out the difference between a[0] and a[0:1] one returns a shape () and the other returns a shape (1,) for 1D list

            – Justice_Lords
            Mar 6 at 8:07











          • Yes, I understand the rule of retaining a degenerated dimension. However, I donot understand why retaining a degenerated dimension prevents the array from permutation. In another word, why not a[0:1,0,[0,3]] returns a shape of (2,1,4)?

            – Liang Guo
            Mar 7 at 9:41
















          You have answered wherein you have to comment. You can understand if you try out the difference between a[0] and a[0:1] one returns a shape () and the other returns a shape (1,) for 1D list

          – Justice_Lords
          Mar 6 at 8:07





          You have answered wherein you have to comment. You can understand if you try out the difference between a[0] and a[0:1] one returns a shape () and the other returns a shape (1,) for 1D list

          – Justice_Lords
          Mar 6 at 8:07













          Yes, I understand the rule of retaining a degenerated dimension. However, I donot understand why retaining a degenerated dimension prevents the array from permutation. In another word, why not a[0:1,0,[0,3]] returns a shape of (2,1,4)?

          – Liang Guo
          Mar 7 at 9:41





          Yes, I understand the rule of retaining a degenerated dimension. However, I donot understand why retaining a degenerated dimension prevents the array from permutation. In another word, why not a[0:1,0,[0,3]] returns a shape of (2,1,4)?

          – Liang Guo
          Mar 7 at 9:41

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54986672%2fpython-array-indexed-with-list-but-array-dimensions-are-permuted%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

          Алба-Юлія

          Захаров Федір Захарович