def _broadcast_shape(*args):
"""Returns the shape of the ararys that would result from broadcasting the
supplied arrays against each other.
"""
if not args:
raise ValueError('must provide at least one argument')
if len(args) == 1:
# a single argument does not work with np.broadcast
return np.asarray(args[0]).shape
# use the old-iterator because np.nditer does not handle size 0 arrays
# consistently
b = np.broadcast(*args[:32])
# unfortunately, it cannot handle 32 or more arguments directly
for pos in range(32, len(args), 31):
# ironically, np.broadcast does not properly handle np.broadcast
# objects (it treats them as scalars)
# use broadcasting to avoid allocating the full array
b = broadcast_to(0, b.shape)
b = np.broadcast(b, *args[pos:(pos + 31)])
return b.shape
stride_tricks.py 文件源码
python
阅读 29
收藏 0
点赞 0
评论 0
评论列表
文章目录