numpy.fromfunction(function, shape, **kwargs)
[source]
Construct an array by executing a function over each coordinate.
The resulting array therefore has a value fn(x, y, z)
at coordinate (x, y, z)
.
Parameters: |
|
---|---|
Returns: |
|
Keywords other than dtype
are passed to function
.
>>> np.fromfunction(lambda i, j: i == j, (3, 3), dtype=int) array([[ True, False, False], [False, True, False], [False, False, True]])
>>> np.fromfunction(lambda i, j: i + j, (3, 3), dtype=int) array([[0, 1, 2], [1, 2, 3], [2, 3, 4]])
© 2005–2019 NumPy Developers
Licensed under the 3-clause BSD License.
https://docs.scipy.org/doc/numpy-1.17.0/reference/generated/numpy.fromfunction.html