MCPcopy Create free account
hub / github.com/numpy/numpy / _broadcast_to

Function _broadcast_to

numpy/lib/stride_tricks.py:340–360  ·  view source on GitHub ↗
(array, shape, subok, readonly)

Source from the content-addressed store, hash-verified

338
339
340def _broadcast_to(array, shape, subok, readonly):
341 shape = tuple(shape) if np.iterable(shape) else (shape,)
342 array = np.array(array, copy=False, subok=subok)
343 if not shape and array.shape:
344 raise ValueError('cannot broadcast a non-scalar to a scalar array')
345 if any(size < 0 for size in shape):
346 raise ValueError('all elements of broadcast shape must be non-'
347 'negative')
348 extras = []
349 it = np.nditer(
350 (array,), flags=['multi_index', 'refs_ok', 'zerosize_ok'] + extras,
351 op_flags=['readonly'], itershape=shape, order='C')
352 with it:
353 # never really has writebackifcopy semantics
354 broadcast = it.itviews[0]
355 result = _maybe_view_as_subclass(array, broadcast)
356 # In a future version this will go away
357 if not readonly and array.flags._writeable_no_warn:
358 result.flags.writeable = True
359 result.flags._warn_on_write = True
360 return result
361
362
363def _broadcast_to_dispatcher(array, shape, subok=None):

Callers 2

broadcast_toFunction · 0.85
broadcast_arraysFunction · 0.85

Calls 2

_maybe_view_as_subclassFunction · 0.85
anyFunction · 0.50

Tested by

no test coverage detected