0 votes
in Python by
explain numpy.broadcast_to() in Python

1 Answer

0 votes
by

numpy.broadcast_to() in Python

The numpy.broadcast_to() function broadcasts an array to a new shape.

Syntax

numpy.broadcast_to(array, shape, subok=False)

Parameter

The numpy.broadcast_to() function has three parameters which are as follows: 

array: This parameter represents the array to broadcast.

shape: It signifies the shape of the desired array.

subok:  It is an optional parameter which takes Boolean value. If True, then sub-classes will be passed-through, else the returned array will be forced to be a base-class array (default).

Return

This function returns a read-only view on the original array with the given shape. It is typically not contiguous. 

Example 1

#Python Program explaining
#numpy.broadcast_to() function
import numpy as np
array = np.array([2,3,4])
print ('The original array:')
print (array,"\n")
print ('Applying the broadcast_to function:')
print (np.broadcast_to(array, (3, 3)))

Output

The original array:
[2 3 4]
Applying the broadcast_to() function:
[[2 3 4]
[2 3 4]
[2 3 4]]

Related questions

0 votes
asked May 19, 2022 in Python by john ganales
0 votes
asked May 19, 2022 in Python by john ganales
...