reshape
Change the shape of an array without changing its data. Returns a view if the array is C-contiguous, otherwise returns a copy. Use-1 for one dimension to have its size inferred automatically.
| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
newShape | number[] | — | New shape. One dimension may be -1, in which case it is inferred from the total size. |
NDArray — Array with the specified shape. View when possible, copy otherwise.
flatten
Return a 1-D copy of the array. Unlikeravel, flatten always allocates new memory.
| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
NDArray — A 1-D array containing all elements in row-major (C) order. Always a copy.
ravel
Return a contiguous flattened 1-D array. Returns a view if the array is already C-contiguous, otherwise returns a copy (same data asflatten in that case).
| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
NDArray — A 1-D array. View when the input is C-contiguous, copy otherwise.
squeeze
Remove axes of length 1 from the array shape. Returns a view (no data is copied).| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
axis | number | number[] | undefined | Axis or axes to squeeze. If undefined, all length-1 axes are removed. Raises an error if the specified axis does not have length 1. |
NDArray — View of a with the specified length-1 dimensions removed.
expand_dims
Insert a new axis (dimension of length 1) at the given position. Returns a view.| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
axis | number | number[] | — | Position(s) where the new axis is inserted. Negative values count from the end. |
NDArray — View of a with an additional dimension inserted.
resize
Return a new array with the given shape. If the new size is larger, the data is repeated (cycled). If smaller, the data is truncated. Always returns a new array (not a view).| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input array. |
new_shape | number[] | — | Shape of the output array. |
NDArray — New array with the specified shape, filled by repeating or truncating elements from a.