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

Function broadcast_to

numpy/lib/stride_tricks.py:368–413  ·  view source on GitHub ↗

Broadcast an array to a new shape. Parameters ---------- array : array_like The array to broadcast. shape : tuple or int The shape of the desired array. A single integer ``i`` is interpreted as ``(i,)``. subok : bool, optional If True, then sub-cl

(array, shape, subok=False)

Source from the content-addressed store, hash-verified

366
367@array_function_dispatch(_broadcast_to_dispatcher, module='numpy')
368def broadcast_to(array, shape, subok=False):
369 """Broadcast an array to a new shape.
370
371 Parameters
372 ----------
373 array : array_like
374 The array to broadcast.
375 shape : tuple or int
376 The shape of the desired array. A single integer ``i`` is interpreted
377 as ``(i,)``.
378 subok : bool, optional
379 If True, then sub-classes will be passed-through, otherwise
380 the returned array will be forced to be a base-class array (default).
381
382 Returns
383 -------
384 broadcast : array
385 A readonly view on the original array with the given shape. It is
386 typically not contiguous. Furthermore, more than one element of a
387 broadcasted array may refer to a single memory location.
388
389 Raises
390 ------
391 ValueError
392 If the array is not compatible with the new shape according to NumPy's
393 broadcasting rules.
394
395 See Also
396 --------
397 broadcast
398 broadcast_arrays
399 broadcast_shapes
400
401 Notes
402 -----
403 .. versionadded:: 1.10.0
404
405 Examples
406 --------
407 >>> x = np.array([1, 2, 3])
408 >>> np.broadcast_to(x, (3, 3))
409 array([[1, 2, 3],
410 [1, 2, 3],
411 [1, 2, 3]])
412 """
413 return _broadcast_to(array, shape, subok=subok, readonly=True)
414
415
416def _broadcast_shape(*args):

Callers 9

_count_reduce_itemsFunction · 0.90
tril_indicesFunction · 0.90
triu_indicesFunction · 0.90
test_broadcast_to_raisesFunction · 0.90
test_subclassesFunction · 0.90
test_writeableFunction · 0.90
test_reference_typesFunction · 0.90
_broadcast_shapeFunction · 0.70

Calls 1

_broadcast_toFunction · 0.85

Tested by 5

test_broadcast_to_raisesFunction · 0.72
test_subclassesFunction · 0.72
test_writeableFunction · 0.72
test_reference_typesFunction · 0.72