当前位置:网站首页>numpy数组创建
numpy数组创建
2022-06-29 13:24:00 【starmultiple】
numpy数组创建
import numpy as np
list =[1,2,3,4]
oneArray=np.array(list)
print(list)
print(oneArray)
头
import numpy as np
import random
简单数组及其类型
t1=np.array([1,2,3])
print(t1)#[1 2 3]
print(type(t1))#<class 'numpy.ndarray'>数组类型
t2=np.array(range(10))
print(t2)#[0 1 2 3 4 5 6 7 8 9]
print(type(t2))#<class 'numpy.ndarray'>
快速数组
t3=np.arange(2,10,2)
print(t3)#[2 4 6 8]
print(type(t3))#<class 'numpy.ndarray'>
print(t3.dtype)#int32
numpy的数据类型
t4=np.array(range(1,4),dtype="i2")#2个字节16位
print(t4)#[1 2 3]
print(t4.dtype)#int16
numpy中的bool类型
t5=np.array([1,1,0,1,0,1,0],dtype=bool)
print(t5)#[ True True False True False True False]
print(t5.dtype)#bool
调整数据类型
t6=t5.astype("int8")
print(t6)#[1 1 0 1 0 1 0]
print(t6.dtype)#int8
numpy中的小数
t7=np.array([random.random() for i in range(10)])#默认random.random()为0~1小数
print(t7)#[0.32123244 0.74099132 0.89527163 0.82204031 0.65102081 0.38178552 0.50962158 0.34564249 0.63039987 0.39896338]
print(t7.dtype)#float64
取两位小数
t8=np.round(t7,3)#取三位小数
print(t8)#[0.496 0.981 0.203 0.725 0.056 0.179 0.548 0.934 0.875 0.813]
边栏推荐
- Basic type variable declaration
- 投资人跌下神坛:半年0出手,转行送外卖
- Goby full port scan
- 直觉与实现:Batch Normalization
- 微信小程序:图片秒加水印制作生成
- 喜迎市科协“十大”•致敬科技工作者 | 卢毅:守护电网传输安全的探索者
- 高校女生穿旗袍答辩!网友:导师说论文要是和旗袍一样漂亮就好了
- Appkey when applying for offline packaging of uniapp
- Wechat applet: Halloween avatar box generation tool
- Wechat applet: install B artifact and P diagram, modify wechat traffic main applet source code, Download funny joke diagram, make server free domain name
猜你喜欢

手把手教你在windows上安装mysql8.0最新版本数据库,保姆级教学

Hundreds of CVPR people were recruited as new champions. Emoji became a "court witness". M2 MBP was exposed that the hard disk speed was reduced. Today, more big news is here

灵感收集·创意写作软件评测:Flomo、Obsidian Memo、Napkin、FlowUs

I talked about exception handling for more than half an hour during the interview yesterday

Lecun published a research plan for the next decade: AI autonomous intelligence with a 62 page paper

微信小程序:云开发表白墙微信小程序源码下载免服务器和域名支持流量主收益

leetcode:226. Flip binary tree

文物数字藏品,开启文化传承的新方式

Wechat applet: repair collection interface version cloud development expression package

College girls wear cheongsam to defend! Netizen: the tutor said it would be nice if the paper were as beautiful as the cheongsam
随机推荐
微信小程序:装B神器P图修改微信流量主小程序源码下载趣味恶搞图制作免服务器域名
Want to make a wechat game for answering questions? Reading this article is enough
Normalization layer of pytorch learning (batchnorm, layernorm, instancenorm, groupnorm) [easy to understand]
【VEUX开发者工具的使用-getters使用】
Hundreds of CVPR people were recruited as new champions. Emoji became a "court witness". M2 MBP was exposed that the hard disk speed was reduced. Today, more big news is here
【 网络带宽 】MBps & Mbps
Applet Wechat: un nouveau réseau exclusif de microgroupes de développement de Cloud
Sixty years of deep learning
纳人才,谋发展 | 人大金仓喜获“最佳雇主校招案例奖”
[graduation season] it's worth it all the way over the past four years -- advice from the senior students
台式机主板上保护cpu的盖子安装和拆卸
C language__ VA_ ARGS__ Usage of
Cicd introduction [easy to understand]
Hash hash game system development explanation technology -- hash game system development solution analysis
Goby full port scan
Characteristics of human immaturity
tcpdump如何对特定的tcp标志位进行过滤
TikTok全球短视频霸主地位或被YouTube反超
[high concurrency] cache idea
OpenSSL certificate tool user manual