当前位置:网站首页>Numpy Foundation
Numpy Foundation
2022-07-26 08:54:00 【Miracle Fan】
List of articles
Create array
# Create array
a=np.array([1,2,3])
b=np.array([(1,5,2,3),(4,5,6,7)],dtype=np.float32)
c=np.array([[(1,5,2,3),(4,5,6,7)],[(3,2,1,0),(4,5,6,7)]],dtype=np.float32)
print(a,'\n',b,'\n',c)
[1 2 3]
[[1. 5. 2. 3.]
[4. 5. 6. 7.]]
[[[1. 5. 2. 3.]
[4. 5. 6. 7.]]
[[3. 2. 1. 0.]
[4. 5. 6. 7.]]]
Initialize placeholders
Zero matrix
np.zeros((3,4))# establish 3*4 Of 0 matrix
1 matrix
np.ones((2,3,4),dtype=np.int16)# establish 2*3*4 Matrix , first 2 Is the number of channels
array([[[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]],
[[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]]], dtype=int16)
Evenly spaced array
d=np.arange(10,25,5)# Evenly spaced array , The step value is 5
np.linspace(0,2,9)# Create evenly spaced arrays , Use the number of samples to split the array
data type
data type | |
---|---|
np.int64 | Signed 64 position |
np.float | Double precision floating point |
np.complex | The plural |
np.bool | bool value |
np.object | Python object |
np.string_ | Fixed length string |
np.unicode_ | Fixed length Unicode |
Array information
a.shape
len(a)
b.ndim
e.size
b.dtype
b.dtype.name
b.astype(int)
Array calculation
Arithmetic operations
a-b /np.subtract(a,b) | |
a+b /np.add(a,b) | |
a/b /np.divide(a,b) | |
a*b /np.multiply(a,b) | |
np.exp(a) | |
np.sqrt(a) | |
np.sin(a) /np.cos(a) | |
np.log(a) | |
a.dot(b) | Dot product |
Compare
a=np.array([1,2,3,4])
b=np.array([3,4,5,1])
1.a==b
[False False False False]
2.a<2
[ True False False False]
3.np.array_equal(a,b)
False
Aggregate functions
function | describe |
---|---|
a.sum() | Array summary |
a.min() | Array minimum |
a.max(axis=0) | Maximum by row |
a.cumsum(axis=1) | Accumulate by column |
a.mean() | The average |
a.median() | Median |
a.corrcoef() | Find the correlation coefficient |
np.std(a) | Standard deviation |
Array copy
h=a.view()
Create the same array view , Now change a,h Will change with it , Also known as shallow copy
h=a.copy()
Create a deep copy of the array
Array sorting
a.sort()
a.sort(axis=0)
Sort the array by behavior
边栏推荐
- Neo eco technology monthly | help developers play smart contracts
- In the first year of L2, the upgrade of arbitrum nitro brought a more compatible and efficient development experience
- Oracle 19C OCP 1z0-083 question bank (7-12)
- Study notes of automatic control principle -- dynamic model of feedback control system
- Set of pl/sql
- Spark SQL common date functions
- Sklearn machine learning foundation (linear regression, under fitting, over fitting, ridge regression, model loading and saving)
- SSH,NFS,FTP
- Spark scheduling analysis
- Memory management based on C language - Simulation of dynamic partition allocation
猜你喜欢
6、 Pinda general permission system__ pd-tools-log
SSH,NFS,FTP
【FreeSwitch开发实践】使用SIP客户端Yate连接FreeSwitch进行VoIP通话
idea快捷键 alt实现整列操作
合工大苍穹战队视觉组培训Day6——传统视觉,图像处理
[untitled]
Memory management based on C language - Simulation of dynamic partition allocation
Foundry tutorial: writing scalable smart contracts in various ways (Part 1)
Learning notes of automatic control principle - Performance Analysis of continuous time system
Media at home and abroad publicize that we should strictly grasp the content
随机推荐
Neo eco technology monthly | help developers play smart contracts
Self review ideas of probability theory
OA项目之我的会议(会议排座&送审)
MySQL 8.0 OCP 1z0-908 certification examination question bank 1
Logic of data warehouse zipper table
My meeting of OA project (meeting seating & submission for approval)
Winter vacation homework & Stamp cutting
Arbitrum Nova release! Create a low-cost and high-speed dedicated chain in the game social field
Oracle 19C OCP 1z0-082 certification examination question bank (51-60)
ES6模块化导入导出)(实现页面嵌套)
C#入门系列(三十一) -- 运算符重载
One click deployment of lamp and LNMP scripts is worth having
OA项目之我的会议(查询)
sklearn 机器学习基础(线性回归、欠拟合、过拟合、岭回归、模型加载保存)
The largest number of statistical absolute values --- assembly language
Leetcode and query question summary
tcp 解决short write问题
Database operation skills 7
pl/sql之集合
Study notes of automatic control principle -- dynamic model of feedback control system