Growing matrices columnwise in NumPy

后端 未结 4 727
终归单人心
终归单人心 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:43

    The hstack can work on zero sized arrays:

    import numpy as np
    
    N = 5
    M = 15
    
    a = np.ndarray(shape = (N, 0))
    for i in range(M):
        b = np.random.rand(N, 1)
        a = np.hstack((a, b))
    

提交回复
热议问题