numpy.fromfunction() function – Python (original) (raw)
Last Updated : 29 Aug, 2020
numpy.fromfunction() function construct an array by executing a function over each coordinate and the resulting array, therefore, has a value fn(x, y, z) at coordinate (x, y, z).
Syntax : numpy.fromfunction(function, shape, dtype)
Parameters :
function : [callable] The function is called with N parameters, where N is the rank of shape. Each parameter represents the coordinates of the array varying along a specific axis.
shape : [(N, ) tuple of ints] Shape of the output array, which also determines the shape of the coordinate arrays passed to function.
dtype : [data-type, optional] Data-type of the coordinate arrays passed to function.
Return : The output array.
Code #1 :
Python3
import
numpy as geek
gfg
=
geek.fromfunction(
lambda
i, j: i
*
j, (
4
,
4
), dtype
=
float
)
print
(gfg)
Output :
[[0. 0. 0. 0.]
[0. 1. 2. 3.]
[0. 2. 4. 6.]
[0. 3. 6. 9.]]
Code #2 :
Python3
import
numpy as geek
gfg
=
geek.fromfunction(
lambda
i, j: i
=
=
j, (
3
,
3
), dtype
=
int
)
print
(gfg)
Output :
[[ True False False]
[False True False]
[False False True]]
Similar Reads
- numpy.fromstring() function – Python numpy.fromstring() function create a new one-dimensional array initialized from text data in a string. Syntax : numpy.fromstring(string, dtype = float, count = -1, sep = ' ') Parameters : string : [str] A string that contained the data. dtype : [data-type, optional] Data-type of the array. Default d 1 min read
- numpy.fromiter() function – Python NumPy's fromiter() function is a handy tool for creating a NumPy array from an iterable object. This iterable can be any Python object that provides elements one at a time. The function is especially useful when you need to convert data from a custom data source, like a file or generator, into a Num 2 min read
- numpy.frombuffer() function – Python numpy.frombuffer() function interpret a buffer as a 1-dimensional array. Syntax : numpy.frombuffer(buffer, dtype = float, count = -1, offset = 0) Parameters : buffer : [buffer_like] An object that exposes the buffer interface. dtype : [data-type, optional] Data-type of the returned array, default da 1 min read
- numpy.frompyfunc() in Python numpy.frompyfunc(func, nin, nout) function allows to create an arbitrary Python function as Numpy ufunc (universal function). Parameters: func: [A python function object ] An arbitrary python function nin: [int] Number of input arguments to that function. nout: [int] Number of objects returned by th 2 min read
- numpy.i0() function | Python numpy.i0() function is the modified Bessel function of the first kind, order 0. it's usually denoted by I0. Syntax : numpy.i0(x) Parameters : x : [array_like, dtype float or complex] Argument of the Bessel function. Return : [ndarray, shape = x.shape, dtype = x.dtype] The modified Bessel function ev 1 min read
- Wand function() function in Python function() function is similar to evaluate function. In function() function pixel channels can be manipulated by applies a multi-argument function to pixel channels. Following are the list of FUNCTION_TYPES in Wand: 'undefined''arcsin''arctan''polynomial''sinusoid' Syntax : wand.image.function(funct 1 min read
- numpy.info() function in Python In Numpy we can get all the information about the function, class, or module like what will the parameter and what will be the type of the return value with the help of numpy.info() function. This function returns the help information for a function, class, or module. Syntax: numpy.info(numpy.info(o 1 min read
- numpy.matrix.A() function - Python numpy.matrix.A() function return self as an ndarray object. Syntax : numpy.matrix.A() Parameters : None Return : [ndarray] Return self as an ndarray. Code #1 : # Python program explaining # numpy.matrix.A() function # importing numpy as geek import numpy as geek mat = geek.matrix(geek.arange(9).resh 1 min read
- Function Composition in Python Function composition is a powerful concept where two or more functions are combined in such a way that the output of one function becomes the input for the next. It allows for the creation of complex functionality from simple, reusable building blocks. This concept is widely used in functional progr 6 min read
- Returning a function from a function - Python In Python, functions are first-class objects, allowing them to be assigned to variables, passed as arguments and returned from other functions. This enables higher-order functions, closures and dynamic behavior. Example: [GFGTABS] Python def fun1(name): def fun2(): return f"Hello, {name}!" 5 min read