当前位置:网站首页>Notes | numpy-09 Broadcast
Notes | numpy-09 Broadcast
2022-07-03 04:49:00 【CY3761】
#%%
# radio broadcast (Broadcast) yes numpy For different shapes (shape) How to do the numerical calculation of the array , Arithmetic operations on arrays are usually performed on the corresponding elements
# If two arrays a and b The same shape , The meet a.shape == b.shape, that a*b The result is that a And b Array corresponding bit multiplication . This requires the same dimension , And the length of each dimension is the same
#%%
import numpy as np
a = np.array([1, 2, 3, 4]) # 4r1c
a
#%%
b = np.array([10, 20, 30, 40]) # 4r1c
b
#%%
c = a * b
c
#%%
# When in operation 2 The shapes of arrays are different ,numpy Will automatically trigger the broadcast mechanism
import numpy as np
a = np.array([
[0, 0, 0],
[10, 10, 10],
[20, 20, 20],
[30, 30, 30]
])
a # 4r3c
#%%
b = np.array([1, 2, 3])
b # 1r3c
#%%
""" a Row index 0 0+1=1 0+2=2 0+3=3 a Row index 1 10+1=11 10+2=12 10+3=13 a Row index 2 20+1=21 20+2=22 20+3=23 a Row index 3 30+1=31 30+2=32 30+3=33 """
a + b # take b Bring in the a | a Column correspondence of b The line of | When calculating, it will be calculated in sequence with the same number of edges
#%%
bb = np.tile(b, (4, 1)) # repeat b Dimensions of | 1 Repeat in the vertical direction 2 Repeat horizontally | 4 repeat 4 Time
bb
#%%
a + bb # Equate to a + b
#%%
""" The rules of broadcasting : Let all the input arrays look to the array with the longest shape , The insufficient parts in the shape are all preceded by 1 A filling . The shape of the output array is the maximum value on each dimension of the shape of the input array . If a dimension of the input array has the same length as the corresponding dimension of the output array, or its length is 1 when , This array can be used to calculate , Otherwise mistakes . When the length of a dimension of the input array is 1 when , The first set of values on this dimension is used when calculating along this dimension Simple understanding : For two arrays , Compare each of their dimensions ( Ignore if one of the arrays has no current dimension ), Satisfy : Arrays have the same shape . The value of the current dimension is equal . One of the values of the current dimension is 1. If the conditions are not met , Throw out "ValueError: frames are not aligned" abnormal """
边栏推荐
- [PCL self study: filtering] introduction and use of various filters in PCL (continuously updated)
- Golang -- realize file transfer
- ZABBIX monitoring of lamp architecture (3): zabbix+mysql (to be continued)
- 【工具跑SQL盲注】
- FISCO bcos zero knowledge proof Fiat Shamir instance source code
- [PHP vulnerability weak type] basic knowledge, PHP weak equality, error reporting and bypassing
- Summary of training competition (Lao Li's collection of questions)
- Number of 1 in binary (simple difficulty)
- 论文阅读_中文医疗模型_ eHealth
- Contents of welder (primary) examination and welder (primary) examination in 2022
猜你喜欢
2022 tea master (intermediate) examination questions and tea master (intermediate) examination skills
Contents of welder (primary) examination and welder (primary) examination in 2022
2022 a special equipment related management (elevator) analysis and a special equipment related management (elevator) simulation test
Review the old and know the new: Notes on Data Science
"Niuke brush Verilog" part II Verilog advanced challenge
移动端——uniapp开发记录(公共请求request封装)
2022 t elevator repair simulation examination question bank and t elevator repair simulation examination question bank
Employee attendance management system based on SSM
UiPath实战(08) - 选取器(Selector)
Uipath practice (08) - selector
随机推荐
Web security - CSRF (token)
Learning record of arouter principle
Network security textual research recommendation
2022 tea master (intermediate) examination questions and tea master (intermediate) examination skills
论文阅读_中文NLP_ELECTRA
[luatos sensor] 2 air pressure bmp180
Current market situation and development prospect prediction of global direct energy deposition 3D printer industry in 2022
论文阅读_ICD编码_MSMN
Matplotlib -- save graph
stm32逆向入门
Contents of welder (primary) examination and welder (primary) examination in 2022
The 19th Zhejiang I. barbecue
Market status and development prospects of the global IOT active infrared sensor industry in 2022
移动端——uniapp开发记录(公共请求request封装)
7. Integrated learning
Pyqt control part (II)
The reason why the entity class in the database is changed into hump naming
Hire cashier (differential constraint)
有道云笔记
Shell script Basics - basic grammar knowledge