MCPcopy Create free account
hub / github.com/numpy/numpy / vectorize

Class vectorize

numpy/lib/function_base.py:2118–2522  ·  view source on GitHub ↗

vectorize(pyfunc=np._NoValue, otypes=None, doc=None, excluded=None, cache=False, signature=None) Returns an object that acts like pyfunc, but takes arrays as input. Define a vectorized function which takes a nested sequence of objects or numpy arrays as inputs and returns a si

Source from the content-addressed store, hash-verified

2116
2117@set_module('numpy')
2118class vectorize:
2119 """
2120 vectorize(pyfunc=np._NoValue, otypes=None, doc=None, excluded=None,
2121 cache=False, signature=None)
2122
2123 Returns an object that acts like pyfunc, but takes arrays as input.
2124
2125 Define a vectorized function which takes a nested sequence of objects or
2126 numpy arrays as inputs and returns a single numpy array or a tuple of numpy
2127 arrays. The vectorized function evaluates `pyfunc` over successive tuples
2128 of the input arrays like the python map function, except it uses the
2129 broadcasting rules of numpy.
2130
2131 The data type of the output of `vectorized` is determined by calling
2132 the function with the first element of the input. This can be avoided
2133 by specifying the `otypes` argument.
2134
2135 Parameters
2136 ----------
2137 pyfunc : callable, optional
2138 A python function or method.
2139 Can be omitted to produce a decorator with keyword arguments.
2140 otypes : str or list of dtypes, optional
2141 The output data type. It must be specified as either a string of
2142 typecode characters or a list of data type specifiers. There should
2143 be one data type specifier for each output.
2144 doc : str, optional
2145 The docstring for the function. If None, the docstring will be the
2146 ``pyfunc.__doc__``.
2147 excluded : set, optional
2148 Set of strings or integers representing the positional or keyword
2149 arguments for which the function will not be vectorized. These will be
2150 passed directly to `pyfunc` unmodified.
2151
2152 .. versionadded:: 1.7.0
2153
2154 cache : bool, optional
2155 If `True`, then cache the first function call that determines the number
2156 of outputs if `otypes` is not provided.
2157
2158 .. versionadded:: 1.7.0
2159
2160 signature : string, optional
2161 Generalized universal function signature, e.g., ``(m,n),(n)->(m)`` for
2162 vectorized matrix-vector multiplication. If provided, ``pyfunc`` will
2163 be called with (and expected to return) arrays with shapes given by the
2164 size of corresponding core dimensions. By default, ``pyfunc`` is
2165 assumed to take scalars as input and output.
2166
2167 .. versionadded:: 1.12.0
2168
2169 Returns
2170 -------
2171 out : callable
2172 A vectorized function if ``pyfunc`` was provided,
2173 a decorator otherwise.
2174
2175 See Also

Calls

no outgoing calls