Efficient way to add a singleton dimension to a NumPy vector so that slice assignments work

前端 未结 5 881
清歌不尽
清歌不尽 2020-12-11 00:48

In NumPy, how can you efficiently make a 1-D object into a 2-D object where the singleton dimension is inferred from the current object (i.e. a list should go to either a 1x

5条回答
  •  没有蜡笔的小新
    2020-12-11 01:16

    You can always use dstack() to replicate your array:

    import numpy
    
    my_list = array([1,2,3,4])
    my_list_2D = numpy.dstack((my_list,my_list));
    

提交回复
热议问题