numpy.broadcast_to()函數將數組廣播為新形狀。
用法: numpy.broadcast_to(array, shape, subok = False)
參數:
array:[array_liket]要廣播的數組。
shape:[元組]所需數組的形狀。
subok:[bool,可選]如果為True,則子類將為passed-through,否則默認情況下,返回的數組將被強製為base-class數組。
Return:[array]輸出數組。
代碼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)
輸出:
[[1 2 3 4]
[1 2 3 4]
[1 2 3 4]
[1 2 3 4]]
代碼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)
輸出:
[[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]]
相關用法
- Python numpy.ma.where()用法及代碼示例
- Python numpy.cov()用法及代碼示例
- Python numpy.ix_()用法及代碼示例
- Python numpy.issubdtype()用法及代碼示例
- Python numpy.issubsctype()用法及代碼示例
- Python Numpy MaskedArray.all()用法及代碼示例
- Python numpy.shares_memory()用法及代碼示例
- Python Numpy MaskedArray.any()用法及代碼示例
- Python numpy.common_type()用法及代碼示例
- Python numpy.may_share_memory()用法及代碼示例
- Python numpy.finfo()用法及代碼示例
- Python numpy.char.add()用法及代碼示例
- Python numpy.obj2sctype()用法及代碼示例
- Python numpy.iinfo()用法及代碼示例
- Python Numpy recarray.max()用法及代碼示例
- Python numpy.promote_types()用法及代碼示例
- Python numpy.ma.masked_values()用法及代碼示例
- Python numpy.ma.fix_invalid()用法及代碼示例
注:本文由純淨天空篩選整理自sanjoy_62大神的英文原創作品 numpy.broadcast_to() function – Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。