tf.keras.ops.vectorize
Stay organized with collections Save and categorize content based on your preferences.
Turn a function into a vectorized function.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-07 UTC."],[],[]]