Friday, October 3, 2025
HomeLanguagesnumpy.broadcast_to() function – Python

numpy.broadcast_to() function – Python

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

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

Parameters :

array : [array_liket] The array to broadcast.

shape : [tuple] The shape of the desired array.

subok : [bool, optional] If True, then sub-classes will be passed-through, otherwise by default, the returned array will be forced to be a base-class array.

Return : [array] The output array.

Code #1 :

Python3




# Python program explaining
# numpy.broadcast_to() function
   
# importing numpy as geek
import numpy as geek
   
arr = geek.array([1, 2, 3, 4])
  
gfg = geek.broadcast_to(arr, (4, 4))
   
print(gfg)


Output :

[[1 2 3 4]

[1 2 3 4]

[1 2 3 4]

[1 2 3 4]]

Code #2 :

Python3




# Python program explaining
# numpy.broadcast_to() function
   
# importing numpy as geek
import numpy as geek
   
arr = geek.array([1, 2, 3, 4, 5])
  
gfg = geek.broadcast_to(arr, (5, 5))
   
print(gfg)


Output :

[[1 2 3 4 5]

[1 2 3 4 5]

[1 2 3 4 5]

[1 2 3 4 5]

[1 2 3 4 5]]

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32332 POSTS0 COMMENTS
Milvus
85 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11868 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11929 POSTS0 COMMENTS
Shaida Kate Naidoo
6819 POSTS0 COMMENTS
Ted Musemwa
7080 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6776 POSTS0 COMMENTS