当前位置:网站首页>Competition notes: numpy learning notes
Competition notes: numpy learning notes
2022-07-19 12:32:00 【Raine_ Yang】
ndarray Provides more array operations than ordinary lists , Accept the following parameters :
numpy.array(object, dtype = None, copy = True, order = None, subok = False, ndmin = 0)
Create array
import numpy as np # Import and stock in first
a = np.array([1, 2, 3])
Create a 2D array
a = np.array([[1, 2], [3, 4]])
Create array , Customize the minimum dimension
a = np.array([1, 2, 3, 4, 5], ndmin = 3)
here a As a three-dimensional array [ [ [1, 2, 3, 4, 5] ] ]
Set data type
import numpy as np
a = np.array([1, 2, 3], dtype = complex)
here a The element in is stored in plural form , That is to say 1 + 0i, 2 + 0i, 3 + 0i
arange() Function to quickly create a one-dimensional array
arange(start, end, step)
start: Starting value , Included in the array
end: Final value , Not included in the array
step: step , Tolerance
arr = np.arange(1, 6, 1) # [1, 2, 3, 4, 5]
linspace()
linspace(start, end, elements)
start: Starting value , Included in the array
end: Final value , Included in the array
elements: Number of elements in the array
arr = np.linspace(1, 11, 10)
''' [ 1. 2.11111111 3.22222222 4.33333333 5.44444444 6.55555556 7.66666667 8.77777778 9.88888889 11. ] '''
ones()
Generate all 1 Array of
np.ones(shape = (row, col), dtype = type)
row: Array rows
col: Number of array columns
type: Array data type
zeros()
Generate all 0 Array of
np.zeros(shape = (row, col), dtype = type)
row: Array rows
col: Number of array columns
type: Array data type
Get array properties
ndim Dimension of array , Represents how many dimensional arrays , return 2, Then it represents a two-dimensional array
shape Dimension of array , Returns the number of rows and columns of the array
size Returns the number of elements in the array
dtype Returns the type of the element in the array
arr = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
print(arr)
print(arr.ndim) # 2
print(arr.shape) # (2, 5)
print(arr.size) # 10
print(arr.dtype) # int32
notes :dtype Return the highest precision data , For example, if 2 Change it to 2.0,dtype Returns the float64, At this time, all the numbers are float64.Numpy Array requires all elements to be of the same type , It depends on the number with the highest accuracy
Array index
One dimensional array operation is the same as list ,arr[ i ] Get a single element ,arr[i : j] Get multiple elements ( Left closed right open interval , Include a[ i ], barring a[ j ])
arr = np.array([1, 2, 3, 4, 5])
print(arr[1]) # Array subscript from 0 Start , The return position is 1 The elements of
# 2
print(arr[0:2]) # Slicing operation , The middle is separated by a colon , The return position is 0,1 The elements of
# [1 2]
Two dimensional array operations
arr[i, j] Get a single element ,arr[i1 : i2, j1 : j2] Get slice , The slice is still left closed and right open
arr2 = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
print(arr2[0:2, 0:2]) # Slice operation of two-dimensional array , Row index before comma , Then the column index , Column index positions are separated by colons
[[1 2]
[6 7]]
Non standard range , Just write : Represents selecting the whole row or column
print(arr2[:, 0:1]) # The default row index is all rows of the array , The first 1 Column
>>>
[[1.]
[6.]]
print(arr2[0:1, :]) # The default column index is all columns of the array , The first 1 That's ok
>>>
[[1. 2. 3. 4. 5.]
Numpy Statistical function
sum Sum up
mean The average
var equation
std Standard deviation
max Maximum
min minimum value
Reference article
https://blog.csdn.net/qq_44039983/article/details/123369799?spm=1001.2101.3001.6650.16&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-16-123369799-blog-79580734.pc_relevant_multi_platform_whitelistv1_exp2&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-16-123369799-blog-79580734.pc_relevant_multi_platform_whitelistv1_exp2&utm_relevant_index=24
边栏推荐
- NPC, Microsoft, etc. proposed inclusivefl: inclusive federal learning on heterogeneous devices
- 第四天作业
- JS chain call sleep function ------ "autumn trick punch in Chapter 2"
- 电路故障的分析简略
- 动态内存规划
- Genesis and bluerun ventures have in-depth exchanges
- GET 请求和 POST 请求的区别和使用
- Figure execution engine (II)
- Experiment the next day
- 01 knapsack interview questions series (I)
猜你喜欢
随机推荐
Mysql-1366 - Incorrect string value: ‘\xE5\xBC\xA0\xE4\xB8\x89‘ for column ‘userName‘ at row 1
2022安全员-C证上岗证题目及答案
结构体内存对齐、位段、联合
PyTorch版:集成注意力和MobileNet的YOLOv4
HCIP(8)
Configuring OSPF experiment in mGRE environment
What is the relationship between softmax and cross enterprise?
JS chain call sleep function ------ "autumn trick punch in Chapter 2"
Array de duplication array sorting maximum sum class array conversion filter array
Travail du quatrième jour
Core base station_ The error "no gateways configured" is reported when starting the CPA file
深度学习参数初始化(二)Kaiming初始化 含代码
Relationship and difference between wav and PCM
String correlation function (II)
Familiar with nestjs (beginner)
PPPoE dial up
Deep learning parameter initialization (II) Kaiming initialization with code
Hcip fourth day notes
超声波传感器(CH101&ch201) - Ⅱ
OpenCV 教程 03: 如何跟踪视频中的某一对象









