This is a pre-release version (2.0.0.dev0+git20260907.41eeb59).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / _external / array_api_extra / _delegation / atleast_nd

function

scipy._external.array_api_extra._delegation:atleast_nd

source: build-install/usr/lib/python3.14/site-packages/scipy/_external/array_api_extra/_delegation.py:59

Signature

def atleast_nd(x: Array, /, ndim: int, xp: ArrayNamespace | 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)
⚠
Traceback (most recent call last):
  File "<doctest scipy._external.array_api_extra._delegation:atleast_nd[0]>", line 1, in <module>
    xpx.atleast_nd(x, ndim=3, xp=xp)
    ^^^
NameError: name 'xpx' is not defined
x = xp.asarray([[[1, 2],
                 [3, 4]]])
xpx.atleast_nd(x, ndim=1, xp=xp) is x
⚠
Traceback (most recent call last):
  File "<doctest scipy._external.array_api_extra._delegation:atleast_nd[0]>", line 1, in <module>
    xpx.atleast_nd(x, ndim=1, xp=xp) is x
    ^^^
NameError: name 'xpx' is not defined

Aliases

  • scipy.differentiate.xpx.atleast_nd