#%% md
+ 选中, 按m, 转为md区块
+ 双击左边 In 或 Out 部分, 进行隐藏处理
+ 光标放到代码位, 按 shift+tab 可以看到代码提示(传入参数等)
+ 代码提示 https://blog.csdn.net/cjw12581/article/details/104835296 (好像可以)
+ inport 的代码提示需要重新输入
#%% md
## 数组的不同创建方式
#%%
import numpy as np
#%%
a = np.ones(10) # shape 创建多少个 | ones(shape,
[(_, type(_)) for _ in a] # 使用列表生成式进行遍历打印
#%%
b = np.zeros(5) # zeros(shape, 默认第一个就是 shape 可以省略关键字
[(_, type(_)) for _ in b]
#%%
c = np.full(10, fill_value=3.14) # fill_value 每个元素都是这个值
[(_, type(_)) for _ in c]
#%%
d = np.random.randint(0, 100, 10) # randint(low, high=None, size=None, dtype=int) | 最小范围 最大范围 分多少份 (随机多少个整数)
[(_, type(_)) for _ in d]
#%%
e = np.random.randn(10) # 正态分布 | https://baike.baidu.com/item/正态分布 | 中间高, 两边低 平均值 0, 标准差(波动) 1
[(_, type(_)) for _ in e]
#%%
f = np.linspace(1,100,99) # np.linspace(start,stop,num=50,endpoint=True,retstep=False,dtype=None,axis=0) | 等差数列
[(_, type(_)) for _ in f] # 具有小数
#%%
f = np.linspace(1,100,100) # np.linspace(start,stop,num=50,endpoint=True,retstep=False,dtype=None,axis=0) | 等差数列
[(_, type(_)) for _ in f] # 没有小数
#%%
f = np.linspace(1,100,50) # np.linspace(start,stop,num=50,endpoint=True,retstep=False,dtype=None,axis=0) | 等差数列
[(_, type(_)) for _ in f] # 有小数
#%%
f = np.linspace(1,99,50) # np.linspace(start,stop,num=50,endpoint=True,retstep=False,dtype=None,axis=0) | 等差数列
[(_, type(_)) for _ in f] # 无小数
#%%
np.set_printoptions(suppress=True) # 不使用科学计数法显示
e = np.logspace(0, 10, 11,base=2) # np.logspace( start, stop, num=50,endpoint=True,base=10.0,dtype=None,axis=0,) | 等比数列
print(e) # 默认这样打印是科学计数法
[(_, type(_)) for _ in e] #
#%%
e = np.logspace(0, 10, 11,base=3) # np.logspace( start, stop, num=50,endpoint=True,base=10.0,dtype=None,axis=0,) | 等比数列
print(e) # 默认这样打印是科学计数法
[(_, type(_)) for _ in e] #
#%%
f = np.random.randint(0, 10, (3,5)) # 二维数组 创建3行 每行5列
[(_, type(_)) for _ in f]
#%%
f = np.random.randint(0, 10, (2,3,4)) # 三维 x,y,z
[(_, type(_)) for _ in f]
#%%
PY-NumPy | 数组创建
最新推荐文章于 2024-10-11 16:17:26 发布