当前位置:网站首页>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)
#%%
边栏推荐
- C Primer Plus Chapter 10, question 14 3 × 5 array
- Uipath practice (08) - selector
- Introduction to JVM principle
- The current market situation and development prospect of the global gluten tolerance test kit industry in 2022
- C primre plus Chapter 10 question 6 inverted array
- 第十九届浙江省 I. Barbecue
- Market status and development prospect prediction of the global fire extinguisher industry in 2022
- Number of uniform strings of leetcode simple problem
- JVM原理简介
- Introduction to message queuing (MQ)
猜你喜欢

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

【工具跑SQL盲注】

M1 Pro install redis

Web security - CSRF (token)

论文阅读_清华ERNIE

《牛客刷verilog》Part II Verilog进阶挑战

Concurrent operation memory interaction

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

The programmer went to bed at 12 o'clock in the middle of the night, and the leader angrily scolded: go to bed so early, you are very good at keeping fit

Basic use of Metasploit penetration testing framework
随机推荐
【SQL注入点】注入点出现位置、判断
2022 registration examination for safety production management personnel of hazardous chemical production units and examination skills for safety production management personnel of hazardous chemical
Employee attendance management system based on SSM
The reason why the entity class in the database is changed into hump naming
Uipath practice (08) - selector
Reptile exercise 03
JS multidimensional array to one-dimensional array
Market status and development prospects of the global automatic tea picker industry in 2022
[SQL injection] joint query (the simplest injection method)
【SQL注入】联合查询(最简单的注入方法)
Thesis reading_ Tsinghua Ernie
String matching: find a substring in a string
C Primer Plus Chapter 10, question 14 3 × 5 array
Number of 1 in binary (simple difficulty)
Leetcode simple question: check whether the array is sorted and rotated
ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
Php+mysql registration landing page development complete code
Preparation for school and professional cognition
Priv app permission exception
Crazy scientist