Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.ma.fromfunction

numpy.ma.fromfunction(function,shape,**kwargs) = <numpy.ma.core._convert2ma object>

Construct an array by executing a function over each coordinate.

The resulting array therefore has a valuefn(x,y,z) atcoordinate(x,y,z).

Parameters:
function:callable

The function is called with N parameters, where N is the rank ofshape. Each parameter represents the coordinates of the arrayvarying along a specific axis. For example, ifshapewere(2,2), then the parameters would bearray([[0,0],[1,1]]) andarray([[0,1],[0,1]])

shape:(N,) tuple of ints

Shape of the output array, which also determines the shape ofthe coordinate arrays passed tofunction.

dtype:data-type, optional

Data-type of the coordinate arrays passed tofunction.By default,dtype is float.

Returns:
fromfunction:any

The result of the call tofunction is passed back directly.Therefore the shape offromfunction is completely determined byfunction. Iffunction returns a scalar value, the shape offromfunction would match theshape parameter.

See also

indices,meshgrid

Notes

Keywords other thandtype are passed tofunction.

Examples

>>>np.fromfunction(lambdai,j:i==j,(3,3),dtype=int)array([[ True, False, False],       [False,  True, False],       [False, False,  True]])
>>>np.fromfunction(lambdai,j:i+j,(3,3),dtype=int)array([[0, 1, 2],       [1, 2, 3],       [2, 3, 4]])

Previous topic

numpy.ma.frombuffer

Next topic

numpy.ma.empty

Quick search

  • © Copyright 2008-2018, The SciPy community.
  • Last updated on Jul 24, 2018.
  • Created usingSphinx 1.6.6.

[8]ページ先頭

©2009-2025 Movatter.jp