📜  numpy.broadcast_to()函数– Python

📅  最后修改于: 2022-05-13 01:54:45.625000             🧑  作者: Mango

numpy.broadcast_to()函数– Python

numpy.broadcast_to()函数将数组广播到新形状。

代码#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)


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)


输出 :

代码#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)

输出 :