Contruct 3d array in numpy from existing 2d array

前端 未结 3 754
终归单人心
终归单人心 2021-02-18 23:57

During preparing data for NumPy calculate. I am curious about way to construct:

myarray.shape => (2,18,18)

from:

d1.shape          


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-19 00:22

    Just doing d3 = array([d1,d2]) seems to work for me:

    >>> from numpy import array
    >>> # ... create d1 and d2 ...
    >>> d1.shape
    (18,18)
    >>> d2.shape
    (18,18)
    >>> d3 = array([d1, d2])
    >>> d3.shape
    (2, 18, 18)
    

提交回复
热议问题