python如何对数组进行降维
作者:青春小尾巴- 时间:2022-12-27 18:51:32
python数组进行降维
在深度学习训练过程中,我们有时候想要输出图片看看图片长什么样,但是训练时的图片格式一般都会多出一个批次的维度,如[1,400,400,3]
这时我们需要把第1个维度去掉才能展示图片:
(1)如果是array的格式,可以直接:img = img.squeeze()
(2)如果是tensor格式图片,可以用img = tf.squeeze(img, [0])
(3)tensor格式图片想增加维度:img = tf.expand_dims(img, 0)
python数组快速降维
python数组多维降维、多维降为一维,快速简便
代码
X=[[[1,2,3],[4,5,6],[7,8,9]]]
X=[x for y in X for x in y]
运行结果
numpy的升维和降维
numpy的升维
a = np.array([1,2])
b = np.expand_dims(a, axis=1)
numpy的降维
a = np.array([[1],[2]])
b = np.squeeze(a)
来源:https://blog.csdn.net/qq_37401585/article/details/115485129
标签:python,数组,降维
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python matplotlib实现折线图的绘制
2022-05-03 11:14:58
![](https://img.aspxhome.com/file/2023/1/93621_0s.png)
支持中文的Len, Left, Right函数
2008-03-18 13:50:00
Python入门_学会创建并调用函数的方法
2023-10-14 17:12:22
![](https://img.aspxhome.com/file/2023/4/66794_0s.jpg)
PHP IN_ARRAY 函数使用注意事项
2023-11-16 19:24:24
Python银行系统实战源码
2022-05-14 14:16:56
Python Excel数据处理之xlrd/xlwt/xlutils模块详解
2022-03-28 16:45:53
![](https://img.aspxhome.com/file/2023/9/103679_0s.png)
echarts学习之legend点击事件解读
2024-05-03 11:10:17
![](https://img.aspxhome.com/file/2023/4/132704_0s.png)
Java连接数据库oracle中文乱码解决方案
2024-01-19 02:48:10
![](https://img.aspxhome.com/file/2023/1/79231_0s.png)
Python 代码实现各种酷炫功能
2022-12-24 10:40:16
![](https://img.aspxhome.com/file/2023/3/134723_0s.png)
匹配 IP 地址与域名的正则表达式
2023-06-17 05:55:48
FLASH 全屏播放
2008-07-19 11:36:00
vue3动态路由刷新后空白或者404问题的解决
2023-07-02 16:58:39
Python __slots__的使用方法
2023-11-19 16:15:10
python添加列表元素append(),extend()及 insert()
2021-03-07 06:17:50
用OpenCV将视频分解成单帧图片,图片合成视频示例
2023-04-25 22:55:03
Python sorted函数详解(高级篇)
2021-08-14 15:58:28
Python实现的Kmeans++算法实例
2023-01-05 22:28:36
MySQL的WHERE语句中BETWEEN与IN的使用教程
2024-01-28 22:37:31
![](https://img.aspxhome.com/file/2023/6/129916_0s.png)
Python pip 安装与使用(安装、更新、删除)
2022-07-30 01:58:19
浅谈使用Python变量时要避免的3个错误
2022-06-20 21:07:07