torchoutil.extras.numpy.functional module

is_numpy_bool_array(
x: Any,
) typing_extensions.TypeGuard[bool_ | ndarray][source]
is_numpy_number_like(
x: Any,
) typing_extensions.TypeGuard[ndarray | number][source]

Returns True if x is an instance of a numpy number type, a np.bool_ or a zero-dimensional numpy array. If numpy is not installed, this function always returns False.

is_numpy_scalar_like(
x: Any,
) typing_extensions.TypeGuard[ndarray | generic][source]

Returns True if x is an instance of a numpy number type or a zero-dimensional numpy array. If numpy is not installed, this function always returns False.

ndarray_to_tensor(
x: Tensor,
*,
dtype: str | dtype | None = None,
force: bool = False,
) ndarray[source]

Convert PyTorch tensor to numpy array.

numpy_all_eq(
x: generic | ndarray,
dim: Literal[None] = None,
) bool[source]
numpy_all_eq(
x: generic | ndarray,
dim: int,
) ndarray
numpy_all_ne(
x: generic | ndarray,
) bool[source]
numpy_complex_dtype_to_float_dtype(
dtype: dtype,
) dtype[source]

Returns the associated float dtype from complex dtype. If input dtype is not complex, it just returns the same dtype.

numpy_is_complex(
x: ndarray | generic,
) bool[source]
numpy_is_complex_dtype(
dtype: dtype,
) bool[source]
numpy_is_floating_point(
x: ndarray | generic,
) bool[source]
numpy_item(
x: ndarray | generic | bool | int | float | complex | None | str | bytes,
) generic[source]
numpy_to_tensor(
x: ndarray | number,
*,
device: device | None | Literal['default', 'cuda_if_available'] | str | int = None,
dtype: dtype | None | Literal['default'] | str | DTypeEnum = None,
) Tensor[source]

Convert numpy array to PyTorch tensor.

numpy_topk(
x: ndarray,
k: int,
dim: int = -1,
largest: bool = True,
sorted: bool = True,
) Tuple[ndarray, ndarray][source]
numpy_view_as_complex(
x: ndarray,
) ndarray[source]

Convert complex array to float array.

Args:

x: The input float array of any shape (…, 2)

Returns:

x_real: The same data in a complex array of shape (…,)

numpy_view_as_real(
x: ndarray,
) ndarray[source]

Convert complex array to float array.

Args:

x: The input complex array of any shape (…,)

Returns:

x_real: The same data in a float array of shape (…, 2)

tensor_to_ndarray(
x: Tensor,
*,
dtype: str | dtype | None = None,
force: bool = False,
) ndarray[source]

Convert PyTorch tensor to numpy array.

tensor_to_numpy(
x: Tensor,
*,
dtype: str | dtype | None = None,
force: bool = False,
) ndarray[source]

Convert PyTorch tensor to numpy array.

to_ndarray(
x: Tensor | ndarray | Iterable | bool | int | float | complex | None | str | bytes,
*,
dtype: str | dtype | None = None,
force: bool = False,
) ndarray[source]

Convert input to numpy array. Works with any arbitrary object.

to_numpy(
x: Tensor | ndarray | Iterable | bool | int | float | complex | None | str | bytes,
*,
dtype: str | dtype | None = None,
force: bool = False,
) ndarray[source]

Convert input to numpy array. Works with any arbitrary object.