initialize a numpy array

前端 未结 12 1720
情歌与酒
情歌与酒 2020-11-28 02:55

Is there way to initialize a numpy array of a shape and add to it? I will explain what I need with a list example. If I want to create a list of objects generated in a loop,

12条回答
  •  半阙折子戏
    2020-11-28 03:28

    Array analogue for the python's

    a = []
    for i in range(5):
        a.append(i)
    

    is:

    import numpy as np
    
    a = np.empty((0))
    for i in range(5):
        a = np.append(a, i)
    

提交回复
热议问题