{ } Raw JSON

bundles / scipy 1.17.1 / scipy / _lib / array_api_extra / _delegation / atleast_nd

function

scipy._lib.array_api_extra._delegation:atleast_nd

source: /scipy/_lib/array_api_extra/_delegation.py :34

Signature

def   atleast_nd ( x : Array / ndim : int xp : ModuleType | None = None )  →  Array

Summary

Recursively expand the dimension of an array to at least ndim.

Parameters

x : array

Input array.

ndim : int

The minimum number of dimensions for the result.

xp : array_namespace, optional

The standard-compatible namespace for x. Default: infer.

Returns

: array

An array with res.ndim >= ndim. If x.ndim >= ndim, x is returned. If x.ndim < ndim, x is expanded by prepending new axes until res.ndim equals ndim.

Examples

import array_api_strict as xp
import array_api_extra as xpx
x = xp.asarray([1])
xpx.atleast_nd(x, ndim=3, xp=xp)
x = xp.asarray([[[1, 2],
                 [3, 4]]])
xpx.atleast_nd(x, ndim=1, xp=xp) is x

Aliases

  • scipy.differentiate.xpx.atleast_nd