cast

ivy.cast(x, dtype_str, f=None)[source]

Casts an array to a specified type.

Parameters
  • x (array) – Input array containing elements to cast.

  • dtype_str (data-type string) – The desired data-type for the array in string format, i.e. ‘float32’ or ‘int64’. If not given, then the type will be determined as the minimum type required to hold the objects in the sequence.

  • f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.

Returns

A new array of the same shape as input array a, with data type given by dtype_str.


Supported Frameworks:

empty jax_logo empty tf_logo empty pytorch_logo empty mxnet_logo empty numpy_logo empty