当前位置:网站首页>Notes | numpy-07 Slice and index
Notes | numpy-07 Slice and index
2022-07-03 04:49:00 【CY3761】
#%%
import numpy as np
a = np.arange(10) # 0~10, Not included 10
a
#%%
s = slice(2, 8, 2) # Construct slice objects
print(s, type(s)) # slice(2, 7, 2) <class 'slice'>
a[s] # From the index 2 Start Indexes 8 end ( Not included 8) step 2
#%%
# Slice parameters can be separated by colons start:stop:step To perform the slicing operation
a[2:8:2] # From the index 2 Start Indexes 8 end ( Not included 8) step 2
#%%
a[5] # Get only one element , The element index is 5
#%%
a[5:] # Get multiple elements , From the index 5 Start to finish
#%%
a[2:5] # Get multiple elements , From the index 2 Start to index 5( Not included 5)
#%%
# Multidimensional arrays
import numpy as np
a = np.array([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
])
a
#%%
# Start cutting from an index
a[1:] # Index from row 1 Start to finish , Get all columns
#%%
# Slices can also include ellipsis …, Make the length of the selection tuple the same as the dimension of the array . If you use an ellipsis at the line position , It will return the that contains the elements in the row ndarray
a[...,1] # The second column of all rows ( Column index 1)
#%%
a[1,...] # And a[1:] Different , Only the row index is obtained here 1 All columns of , When you return, you will first r after c Handle
#%%
a[...,1:] # It can also be cut + Leche Index of all rows 1( Second column ) To the last column (3r2c)
#%%
边栏推荐
- [tools run SQL blind note]
- What is UUID
- Do you know UVs in modeling?
- 2022 chemical automation control instrument examination summary and chemical automation control instrument certificate examination
- Literature reading_ Research on the usefulness identification of tourism online comments based on semantic fusion of multimodal data (Chinese Literature)
- I've been in software testing for 8 years and worked as a test leader for 3 years. I can also be a programmer if I'm not a professional
- Keepalived热备与HAProxy
- Ffmpeg mix
- [set theory] binary relation (example of binary relation operation | example of inverse operation | example of composite operation | example of limiting operation | example of image operation)
- Market status and development prospect forecast of global heat curing adhesive industry in 2022
猜你喜欢

Integration of Android high-frequency interview questions (including reference answers)

FISCO bcos zero knowledge proof Fiat Shamir instance source code

Sdl2 + OpenGL glsl practice (Continued)

String matching: find a substring in a string

2022 registration of G2 utility boiler stoker examination and G2 utility boiler stoker reexamination examination

Two drawing interfaces - 1 Matlab style interface

联发科技2023届提前批IC笔试(题目)

有道云笔记

Do you know UVs in modeling?

JDBC database operation
随机推荐
第十九届浙江省 I. Barbecue
Market status and development prospects of the global automatic tea picker industry in 2022
Market status and development prospect prediction of the global fire alarm sensor industry in 2022
MySQL winter vacation self-study 2022 12 (3)
Youdao cloud notes
Reptile exercise 02
AWS VPC
After job hopping at the end of the year, I interviewed more than 30 companies in two weeks and finally landed
Career planning of counter attacking College Students
Current market situation and development prospect forecast of the global fire boots industry in 2022
2.14 summary
The reason why the entity class in the database is changed into hump naming
[SQL injection] joint query (the simplest injection method)
Triangular rasterization
Hire cashier (differential constraint)
论文阅读_清华ERNIE
Learning practice: comprehensive application of cycle and branch structure (I)
Concurrent operation memory interaction
【SQL注入点】注入点出现位置、判断
文献阅读_基于多模态数据语义融合的旅游在线评论有用性识别研究(中文文献)