当前位置:网站首页>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]
边栏推荐
- ES6 array method
- Intuition and Implementation: batch normalization
- Introduction to reverse commissioning -pe file section table and block 03/07
- PG Basics - logical structure management (1)
- c语言入门教程–-6循环语句
- Stable currency risk profile: are usdt and usdc safe?
- Shell——文本处理命令
- 瑞达期货可以开户吗?安全可靠吗?
- 关于MongoDB报错:connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
- windows平台下的mysql启动等基本操作
猜你喜欢
随机推荐
东莞虎门券商公司股票开户哪个更好更安全?
MySQL数据库:存储引擎
灵感收集·创意写作软件评测:Flomo、Obsidian Memo、Napkin、FlowUs
C language__ VA_ ARGS__ Usage of
Applet Wechat: un nouveau réseau exclusif de microgroupes de développement de Cloud
Matlab fmincon precision, fmincon and quadprog error
Installation and removal of cover for CPU protection on desktop motherboard
Game development of contract quantitative trading system (ready-made case analysis)
goby全端口扫描
Dynamic feedback load balancing strategy based on Cluster
Getting started with SQLite3
zabbix 5.0如何将esxi6.7添加到监控
微信小程序:修复采集接口版云开发表情包
在同花顺上开户安全吗 开户在哪里申请
vmware虚拟机的作用
节点数据采集和标签信息的远程洪泛传输
微信小程序:大红喜庆版UI猜灯谜又叫猜字谜
WinDbg debugging tool introduction
动荡的中介生意,不安的租房人
Notimplementederror: numpy() is only available when Eagle execution is enabled








