tf.keras.ops.vectorize | TensorFlow v2.16.1 (original) (raw)
tf.keras.ops.vectorize
Turn a function into a vectorized function.
View aliases
Main aliases
tf.keras.ops.vectorize(
pyfunc, *, excluded=None, signature=None
)
Example:
def myfunc(a, b):
return a + b
vfunc = np.vectorize(myfunc)
y = vfunc([1, 2, 3, 4], 2) # Returns Tensor([3, 4, 5, 6])
| Args | |
|---|---|
| pyfunc | Callable of a single tensor argument. |
| excluded | Optional set of integers representing positional arguments for which the function will not be vectorized. These will be passed directly to pyfunc unmodified. |
| signature | Optional generalized universal function signature, e.g., "(m,n),(n)->(m)" for vectorized matrix-vector multiplication. If provided,pyfunc will be called with (and expected to return) arrays with shapes given by the size of corresponding core dimensions. By default, pyfunc is assumed to take scalars tensors as input and output. |
| Returns |
|---|
| A new function that applies pyfunc to every element of its input along axis 0 (the batch axis). |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-06-07 UTC.