您现在的位置是:网站首页> 编程资料编程资料
Python数据分析numpy数组的3种创建方式_python_
2023-05-26
395人已围观
简介 Python数据分析numpy数组的3种创建方式_python_
一、使用列表创建numpy数组
1 使用numpy创建一维数组

2 使用numpy创建二维数组

3 使用numpy创建一维数组,源为不同数据类型的列表
如下,源虽然是不同类型的元素的列表,但是创建numpy对象后,都转换为字符串类型,类型的优先级是:字符串 > 浮点数 > 整数

二、通过读取图片创建多维numpy数组
1 将图片信息读取到numpy数组中
首先在jupyter根目录中上传了一张"100.png"的图片,然后使用如下代码即可读取
import matplotlib.pyplot as plt img_arr=plt.imread("./100.png")回显如下:
array([[[1., 1., 1., 1.], [1., 1., 1., 1.], [1., 1., 1., 1.], ..., [1., 1., 1., 1.], [1., 1., 1., 1.], [1., 1., 1., 1.]], [[1., 1., 1., 1.], [1., 1., 1., 1.], [1., 1., 1., 1.], ..., [1., 1., 1., 1.], [1., 1., 1., 1.], [1., 1., 1., 1.]], [[1., 1., 1., 1.], [1., 1., 1., 1.], [1., 1., 1., 1.], ..., [1., 1., 1., 1.], [1., 1., 1., 1.], [1., 1., 1., 1.]], ..., [[1., 1., 1., 1.], [1., 1., 1., 1.], [1., 1., 1., 1.], ..., [1., 1., 1., 1.], [1., 1., 1., 1.], [1., 1., 1., 1.]], [[1., 1., 1., 1.], [1., 1., 1., 1.], [1., 1., 1., 1.], ..., [1., 1., 1., 1.], [1., 1., 1., 1.], [1., 1., 1., 1.]], [[1., 1., 1., 1.], [1., 1., 1., 1.], [1., 1., 1., 1.], ..., [1., 1., 1., 1.], [1., 1., 1., 1.], [1., 1., 1., 1.]]], dtype=float32)
2 在jupyter中读取图片数据后并显示

3 对图片数组数据处理
对数组中每个元素减0.1,图像已经发生了变化

三、通过指定函数生成numpy数组
1 生成多维数组

2 生成一维线性数组

3 生成一维等差数列

4 生成随机的多维数组

到此这篇关于Python数据分析numpy数组的3种创建方式的文章就介绍到这了,更多相关Python numpy数组创建内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
您可能感兴趣的文章:
相关内容
- Python实现yaml与json文件批量互转_python_
- Python pip超详细教程之pip的安装与使用_python_
- 利用Seaborn绘制20个精美的pairplot图_python_
- Python处理时间戳和时间计算等的脚本分享_python_
- Python Flask中Cookie和Session区别详解_python_
- Python使用Flask Migrate模块迁移数据库_python_
- Python制作简易版2048小游戏_python_
- Python flask使用ajax上传文件的示例代码_python_
- 以SortedList为例详解Python的defaultdict对象使用自定义类型的方法_python_
- Python一步步带你操作Excel_python_
