def broadcast_to(self, shape):
"""
Performs the equivalent of np.broadcast_to for COO.
Parameters
----------
shape : tuple[int]
The shape to broadcast the data to.
Returns
-------
The broadcasted sparse array.
Raises
------
ValueError
If the operand cannot be broadcast to the given shape.
"""
result_shape = self._get_broadcast_shape(self.shape, shape, is_result=True)
params = self._get_broadcast_parameters(self.shape, result_shape)
coords, data = self._get_expanded_coords_data(self.coords, self.data, params, result_shape)
return COO(coords, data, shape=result_shape, has_duplicates=self.has_duplicates,
sorted=self.sorted)
评论列表
文章目录