initialize a numpy array

前端 未结 12 1695
情歌与酒
情歌与酒 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条回答
  •  Happy的楠姐
    2020-11-28 03:28

    Introduced in numpy 1.8:

    numpy.full

    Return a new array of given shape and type, filled with fill_value.

    Examples:

    >>> import numpy as np
    >>> np.full((2, 2), np.inf)
    array([[ inf,  inf],
           [ inf,  inf]])
    >>> np.full((2, 2), 10)
    array([[10, 10],
           [10, 10]])
    

提交回复
热议问题