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
- Example 1
- Example 2
- Example 3
use \NDArray as nd;
$a = nd::array([[1, 2], [3, 4]]);
echo nd::expand_dims($a, [0, 1]);
Output
[[[1, 2, 3, 4]]]
use \NDArray as nd;
$a = nd::array([1, 2, 3, 4]);
echo nd::expand_dims($val, -1);
Output
[[1]
[2]
[3]
[4]]
use \NDArray as nd;
$a = nd::array([[1, 2], [3, 4]]);
echo nd::expand_dims($val, 4);
Output
Fatal error: Uncaught Error: invalid axis or axes provided. in /home/henrique/Documentos/Repositórios/numpower/test.php:8
Stack trace:
#0 /home/numpower/test.php(4): NDArray::expand_dims(Object(NDArray), 5)
#1 {main}
thrown in /home/numpower/test.php on line 4
Notes
tip
GPU SUPPORTED
This operation is supported by GPU (VRAM).