Deep copy of a np.array of np.array

前端 未结 3 1492
我寻月下人不归
我寻月下人不归 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:18

    Beaten by one minute. Indeed, deepcopy is the answer here.

    To your second question abut indexing: I have a feeling that you may be better off with a simple list or a dictionary-type data structure here. np.arrays make sense primarily if each array element is of the same type. Of course you can argue that each element in array_of_arrays is another array, but what is the benefit of having them collected in a numpy array instead of a simple list?

    list_of_arrays = [np.arange(a*b).reshape(a,b) for (a, b) in pairs]
    

提交回复
热议问题