How to copy data from a numpy array to another

前端 未结 7 1662
逝去的感伤
逝去的感伤 2020-11-28 03:07

What is the fastest way to copy data from array b to array a, without modifying the address of array a. I need this because an external library (PyFFTW) uses a pointer to my

相关标签:
7条回答
  • 2020-11-28 03:55

    There are many different things you can do:

    a=np.copy(b)
    a=np.array(b) # Does exactly the same as np.copy
    a[:]=b # a needs to be preallocated
    a=b[np.arange(b.shape[0])]
    a=copy.deepcopy(b)
    

    Things that don't work

    a=b
    a=b[:] # This have given my code bugs 
    
    0 讨论(0)
提交回复
热议问题