当前位置:网站首页>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]
边栏推荐
- MySQL数据库:使用show profile命令分析性能
- College girls wear cheongsam to defend! Netizen: the tutor said it would be nice if the paper were as beautiful as the cheongsam
- 喜迎市科协“十大”•致敬科技工作者 | 卢毅:守护电网传输安全的探索者
- 东莞虎门券商公司股票开户哪个更好更安全?
- June training (day 29) - divide and rule
- Follow me study hcie big data mining Chapter 1 Introduction to data mining module 1
- Interpretation of RESNET source code in mmdet +ghost module
- Five years after graduation, I asked all the leaders around me and summarized their learning methods
- Intuition and Implementation: batch normalization
- tcpdump如何对特定的tcp标志位进行过滤
猜你喜欢

微信小程序:修复采集接口版云开发表情包

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

Teach you how to install the latest version of mysql8.0 database on windows, nanny level teaching

windows平台下的mysql启动等基本操作

mysql多表查询

leetcode:226. 翻转二叉树

Intuition and Implementation: batch normalization

Problems in replacing RESNET convolution of mmdet with ghost convolution group

Wechat applet: new and exclusive cloud development wechat group contacts

昨天面试居然聊了半个多小时的异常处理
随机推荐
喜迎市科协“十大”•致敬科技工作者 | 卢毅:守护电网传输安全的探索者
Why does ETL often become ELT or even let?
Xiaobai learns MySQL - incremental statistical SQL requirements - windowing function scheme
嵌入式开发:硬件在环测试
Deecamp2022 officially opened! Likaifu and zhangyaqin personally teach master courses 𞓜 innovation
Korean AI team plagiarizes the shock academic world! One tutor with 51 students, or plagiarism recidivist
Matlab fmincon precision, fmincon and quadprog error
Detailed explanation of PDB symbol library files
Thinkpad VMware 安装虚拟机出现此主机支持 Intel VT-x,但 Intel VT-x 处于禁用状态(问题解决方法)
Sixty years of deep learning
Intuition and Implementation: batch normalization
Wechat applet: Halloween avatar box generation tool
硬件开发笔记(八): 硬件开发基本流程,制作一个USB转RS232的模块(七):创建基础DIP元器件(晶振)封装并关联原理图元器件
golang6 反射
靠代理,靠买断,国产端游的蛮荒时代等待下一个《永劫无间》
MySQL数据库:drop、truncate、delete的区别
[document translation] camouflaged object detection
内网穿透(nc)
机器学习 Out-of-Fold 折外预测详解 | 使用折外预测 OOF 评估模型的泛化性能和构建集成模型
Introduction to reverse commissioning -pe file section table and block 03/07