Growing matrices columnwise in NumPy

后端 未结 4 768
终归单人心
终归单人心 2021-02-12 13:58

In pure Python you can grow matrices column by column pretty easily:

data = []
for i in something:
    newColumn = getColumnDataAsList(i)
    data.append(newColu         


        
4条回答
  •  感情败类
    2021-02-12 14:32

    Usually you don't keep resizing a NumPy array when you create it. What don't you like about your third solution? If it's a very large matrix/array, then it might be worth allocating the array before you start assigning its values:

    x = len(something)
    y = getColumnDataAsNumpyArray.someLengthProperty
    
    data = numpy.zeros( (x,y) )
    for i in something:
       data[i] = getColumnDataAsNumpyArray(i)
    

提交回复
热议问题