原文:https://docs.scipy.org/doc/numpy/reference/generated/numpy.fromfunction.html
校对:(虚位以待)
numpy.fromfunction(function, shape, **kwargs)[source]通过在每个坐标上执行函数来构造数组。
The resulting array therefore has a value fn(x, y, z) at coordinate (x, y, z).
| 参数: | 函数:callable
shape:(N,)ints的元组
dtype:数据类型,可选
|
|---|---|
| 返回: | fromfunction:any
|
笔记
除dtype之外的关键字传递到函数。
例子
>>> np.fromfunction(lambda i, j: i == j, (3, 3), dtype=int)
array([[ True, False, False],
[False, True, False],
[False, False, True]], dtype=bool)
>>> np.fromfunction(lambda i, j: i + j, (3, 3), dtype=int)
array([[0, 1, 2],
[1, 2, 3],
[2, 3, 4]])