PY-NumPy | 数组创建

#%% 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]

#%%



在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CY3761

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值