Skip to main content

NDArray::expand_dims

public static function expand_dims(NDArray|array|float|int $target, int|array $axis = NULL): NDArray;

Adds a new axis to the array at the specified position, thereby expanding its shape.


Parameters

$target

  • Type - NDArray | array | GdImage
  • Target array.

$axis

  • Type - array | int
  • This parameter specifies the position where the new axis (or axes) will be inserted within the expanded array.

Examples

use \NDArray as nd;

$a = nd::array([[1, 2], [3, 4]]);
echo nd::expand_dims($a, [0, 1]);
Output
[[[1, 2, 3, 4]]]

Notes

tip

GPU SUPPORTED

This operation is supported by GPU (VRAM).