def broadcast_shape(shp1, shp2):
"""Broadcast the shape of those arrays
Parameters
----------
shp1 : tuple
shape of array 1
shp2 : tuple
shape of array 2
Returns
-------
tuple
shape resulting from broadcasting two arrays using numpy rules
Raises
------
ValueError
Arrays cannot be broadcasted
"""
try:
return np.broadcast(np.empty(shp1), np.empty(shp2)).shape
except ValueError:
raise ValueError("Arrays cannot be broadcasted - %s and %s " % (str(shp1), str(shp2)))
评论列表
文章目录