numpy.ma.fromfunction(function, shape, **kwargs) =
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: |
function : callable The function is called with N parameters, where N is the rank of shape : (N,) tuple of ints Shape of the output array, which also determines the shape of the coordinate arrays passed to dtype : data-type, optional Data-type of the coordinate arrays passed to |
---|---|
Returns: |
fromfunction : any The result of the call to |
See also
indices
, meshgrid
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]], dtype=bool)
>>> np.fromfunction(lambda i, j: i + j, (3, 3), dtype=int) array([[0, 1, 2], [1, 2, 3], [2, 3, 4]])
© 2008–2017 NumPy Developers
Licensed under the NumPy License.
https://docs.scipy.org/doc/numpy-1.12.0/reference/generated/numpy.ma.fromfunction.html