python, numpy; How to insert element at the start of an array

前端 未结 5 1353
你的背包
你的背包 2021-02-12 10:47

I have an numpy array of complex numbers. So I want to insert zero at start of the array, and shift the rest of the array one place forward.

example:



        
5条回答
  •  星月不相逢
    2021-02-12 11:35

    Also, if you have an n-dimensional array, you need to specify the axis as well, otherwise it gets flattened out:

     np.insert(my_array, 0, myvalue, axis=1)
    

提交回复
热议问题