shape和reshape
2024-09-06 00:46:09
import numpy as np
a = np.array([1,2,3,4,5,6,7,8]) #一维数组
print(a.shape[0]) #值为8,因为有8个数据
print(a.shape[1]) #IndexError: tuple index out of range a = np.array([[1,2,3,4],[5,6,7,8]]) #二维数组
print(a.shape[0]) #值为2,最外层矩阵有2个元素,2个元素还是矩阵。
print(a.shape[1]) #值为4,内层矩阵有4个元素。
print(a.shape[2]) #IndexError: tuple index out of range
a = np.array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]) #一维数组
print(a.reshape(2,8))#建立二维数组,两行八列
print(a.reshape((2,2,2,2)))#建立四维数组
print(a.reshape((2,2,2,2)))#建立四维数组
print(a.reshape((2,4,2)))#建立三维数组
图像重建数组
image = np.array([[[ 0.67826139, 0.29380381],
[ 0.90714982, 0.52835647],
[ 0.4215251 , 0.45017551]],
[[ 0.92814219, 0.96677647],
[ 0.85304703, 0.52351845],
[ 0.19981397, 0.27417313]],
[[ 0.60659855, 0.00533165],
[ 0.10820313, 0.49978937],
[ 0.34144279, 0.94630077]]])
三维数组相当于(3,3,2)
image.shape[0]=3最外层
image.shape[1]=3次外层
image.shape[2]=2最里层
3*3*2=16
经过 v = image.reshape(image.shape[0]*image.shape[1]*image.shape[2],1)
变成 16行,1列
image2vector(image) =
[[0.67826139]
[0.29380381]
[0.90714982]
[0.52835647]
[0.4215251 ]
[0.45017551]
[0.92814219]
[0.96677647]
[0.85304703]
[0.52351845]
[0.19981397]
[0.27417313]
[0.60659855]
[0.00533165]
[0.10820313]
[0.49978937]
[0.34144279]
[0.94630077]]
最新文章
- SVN:Previous operation has not finished; run 'cleanup' if it was interrupted
- 七天学会ASP.NET MVC (三)——ASP.Net MVC 数据处理
- UE4 WCF RestFul 服务器 读取JSON 数据并解析 简单实例
- 用nhibernate的几点小经验
- CSS ID选择器(三)
- Oracle11g 32位安装步骤
- 分享一款简洁的jQuery轮播源码
- 【转载】GDB反向调试(Reverse Debugging)
- pthread_create用法
- php的数组与字符串的转换函数整理
- What is Flux?
- Unitty 3D 贪吃蛇 今日小记 -- 碰撞
- ROS_Kinetic_25 在ubuntu16.04使用Leap_motion并作为手势输入控制Gazebo中的机器人
- day 14 递归、匿名函数、内置函数
- [UOJ317]【NOI2017】游戏 题解
- C_求两个日期相隔的天数(闰年)
- 解决Linux服务器tomact-8.0启动慢的问题
- (原+转)Ubuntu16.04软件中心闪退及wifi消失
- ThinkPHP5命令行 执行控制器下的某方法
- mysqldump对于DB进行逻辑备份的时候,是否会备份视图呢?