View source on GitHub |
Enable NumPy behavior on Tensors.
tf.experimental.numpy.experimental_enable_numpy_behavior(
prefer_float32=False, dtype_conversion_mode='legacy'
)
Enabling NumPy behavior has three effects:
- It adds to
tf.Tensor
some common NumPy methods such asT
,reshape
andravel
. - It changes dtype promotion in
tf.Tensor
operators to be compatible with NumPy. For example,tf.ones([], tf.int32) + tf.ones([], tf.float32)
used to throw a "dtype incompatible" error, but after this it will return a float64 tensor (obeying NumPy's promotion rules). - It enhances
tf.Tensor
's indexing capability to be on par with NumPy's.