expand_dims

sparse.expand_dims(x, /, *, axis=0)[source]

Expands the shape of an array by inserting a new axis (dimension) of size one at the position specified by axis.

Parameters:
  • a (COO) – Input COO array.

  • axis (int) – Position in the expanded axes where the new axis is placed.

Returns:

result – An expanded output COO array having the same data type as x.

Return type:

COO

Examples

>>> import sparse
>>> x = sparse.COO.from_numpy([[1, 0, 0, 0, 2, -3]])
>>> x.shape
(1, 6)
>>> y1 = sparse.expand_dims(x, axis=1)
>>> y1.shape
(1, 1, 6)
>>> y2 = sparse.expand_dims(x, axis=2)
>>> y2.shape
(1, 6, 1)