Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pytensor/tensor/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4247,6 +4247,17 @@ def expand_dims(

Insert a new axis that will appear at the `axis` position in the expanded
array shape.

Parameters
----------
a :
The input array.
axis :
Position in the expanded axes where the new axis is placed.
If `axis` is empty, `a` will be returned immediately.
Returns
-------
`a` with a new axis at the `axis` position.
"""
a = as_tensor(a)

Expand All @@ -4256,6 +4267,9 @@ def expand_dims(
out_ndim = len(axis) + a.ndim
axis = np.core.numeric.normalize_axis_tuple(axis, out_ndim)

if not axis:
return a

dim_it = iter(range(a.ndim))
pattern = ["x" if ax in axis else next(dim_it) for ax in range(out_ndim)]

Expand Down