Deep copy of a np.array of np.array

前端 未结 3 1486
我寻月下人不归
我寻月下人不归 2020-12-20 11:22

I have a numpy array of different numpy arrays and I want to make a deep copy of the arrays. I found out the following:

import numpy as np

pairs = [(2, 3),          


        
3条回答
  •  天命终不由人
    2020-12-20 12:20

    import numpy as np
    import copy
    
    pairs = [(2, 3), (3, 4), (4, 5)]
    array_of_arrays = np.array([np.arange(a*b).reshape(a,b) for (a, b) in pairs])
    
    a = copy.deepcopy(array_of_arrays)
    

    Feel free to read up more about this here.

    Oh, here is simplest test case:

    a[0][0,0]
    print a[0][0,0], array_of_arrays[0][0,0]
    

提交回复
热议问题