NumPy - broadcast_to() function
The NumPy broadcast_to() function broadcasts an array to a new shape.
Returns a read-only view on the original array with the given shape.
In the example below, an array is broadcasted to a given shape.
import numpy as np x = np.array([1, 2, 3]) y = np.array([10, 20]) #x is broadcasted to shape (3,3) x1 = np.broadcast_to(x, (3, 3)) #displaying results print("x1 contains:") print(x1)
The output of the above code will be:
x1 contains: [[1 2 3] [1 2 3] [1 2 3]]
❮ NumPy - Functions