You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expands the shape of an array by inserting a new axis of size one at the position specified by ``axis``.
84
+
Expands the shape of an array by inserting a new axis of size one at the position (or positions) specified by ``axis``.
85
85
86
86
Parameters
87
87
----------
88
88
x: array
89
89
input array.
90
-
axis: int
91
-
axis position (zero-based). A valid ``axis`` **must** reside on the closed-interval ``[-N-1, N]``, where ``N`` is the number of axes in ``x``. If an axis is specified as a negative integer, the axis position at which to insert a singleton dimension **must** be computed as ``N + axis + 1``. Hence, if provided ``-1``, the resolved axis position **must** be ``N`` (i.e., a singleton dimension **must** be appended to the input array ``x``). If provided ``-N-1``, the resolved axis position **must** be ``0`` (i.e., a singleton dimension **must** be prepended to the input array ``x``). If provided an invalid axis, the function **must** raise an exception. Default: ``0``.
90
+
axis: Union[int, Tuple[int, ...]]
91
+
axis position(s) (zero-based). If ``axis`` is an integer, ``axis`` **must** be equivalent to the tuple ``(axis,)``. If ``axis`` is a tuple,
92
+
93
+
- a valid axis position **must** reside on the half-open interval ``[-M, M)``, where ``M = N + len(axis)`` and ``N`` is the number of dimensions in ``x``.
94
+
- if the i-th entry is a negative integer, the axis position of the inserted singleton dimension in the output array **must** be computed as ``M + axis[i]``.
95
+
- each entry of ``axis`` must resolve to a unique positive axis position.
96
+
- for each entry of ``axis``, the corresponding dimension in the expanded output array **must** be a singleton dimension.
97
+
- for the remaining dimensions of the expanded output array, the output array dimensions **must** correspond to the dimensions of ``x`` in order.
98
+
- if provided an invalid axis position, the function **must** raise an exception.
92
99
93
100
Returns
94
101
-------
95
102
out: array
96
-
an expanded output array. **Must** have the same data type as ``x``.
103
+
an expanded output array. **Must** have the same data type as ``x``. If ``axis`` is an integer, the output array must have ``N + 1`` dimensions. If ``axis`` is a tuple, the output array must have ``N + len(axis)`` dimensions.
97
104
98
105
Raises
99
106
------
100
107
IndexError
101
108
If provided an invalid ``axis``, an ``IndexError`` **should** be raised.
109
+
110
+
Notes
111
+
-----
112
+
113
+
- Calling this function with a tuple of axis positions **must** be semantically equivalent to calling this function repeatedly with a single axis position only when the following three conditions are met:
114
+
115
+
- each entry of the tuple is normalized to positive axis positions according to the number of dimensions in the expanded output array.
116
+
- the normalized positive axis positions are sorted in ascending order.
117
+
- the normalized positive axis positions are unique.
0 commit comments