shape和reshape
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]]
shape和reshape的更多相关文章
- caffe进行finetune时出现"shapeequals(proto) shape mismatch (reshape not set)"的解决办法
声明:加载的caffemodel会根据你的net.prototxt文件里的各个layer的name来进行参数赋值. 错误:[Caffe]: Check failed: ShapeEquals(prot ...
- Numpy中的shape和reshape()
shape是查看数据有多少行多少列reshape()是数组array中的方法,作用是将数据重新组织 1.shape import numpy as np a = np.array([1,2,3,4,5 ...
- Python:numpy中shape和reshape的用法
>>> w=np.zeros((5,6))>>> warray([[ 0., 0., 0., 0., 0., 0.], [ 0., 0., ...
- tensorflow.reshap(tensor,shape,name)的使用说明
tensorflow as tf tf.reshape(tensor, shape, name=None) reshape作用是将tensor变换为指定shape的形式. 其中shape为一个列表形式 ...
- tensorflow 基本函数(1.tf.split, 2.tf.concat,3.tf.squeeze, 4.tf.less_equal, 5.tf.where, 6.tf.gather, 7.tf.cast, 8.tf.expand_dims, 9.tf.argmax, 10.tf.reshape, 11.tf.stack, 12tf.less, 13.tf.boolean_mask
1. tf.split(3, group, input) # 拆分函数 3 表示的是在第三个维度上, group表示拆分的次数, input 表示输入的值 import tensorflow ...
- tensorflow的reshape操作tf.reshape()
在处理图像数据的时候总会遇到输入图像的维数不符合的情况,此时tensorflow中reshape()就很好的解决了这个问题. 更为详细的可以参考官方文档说明: numpy.reshape reshap ...
- TensorFlow基础二(Shape)
首先说明tf中tensor有两种shape,分别为static (inferred) shape和dynamic (true) shape,其中static shape用于构建图,由创建这个tenso ...
- 基于Caffe的Large Margin Softmax Loss的实现(上)
小喵的唠叨话:在写完上一次的博客之后,已经过去了2个月的时间,小喵在此期间,做了大量的实验工作,最终在使用的DeepID2的方法之后,取得了很不错的结果.这次呢,主要讲述一个比较新的论文中的方法,L- ...
- 从零开始山寨Caffe·玖:BlobFlow
听说Google出了TensorFlow,那么Caffe应该叫什么? ——BlobFlow 神经网络时代的传播数据结构 我的代码 我最早手写神经网络的时候,Flow结构是这样的: struct Dat ...
随机推荐
- 70.Trapping Rain Water(容水量)
Level: Hard 题目描述: Given n non-negative integers representing an elevation map where the width of e ...
- 微软Visual Studio Code基本特征
Visual Studio Code它的核心功能还是作为一个代码编辑器.和其他的代码编辑器一样,VScode采取通用的UI和布局,浏览器在左边,显示所有的文件和文件夹,右边你打开的文件的编辑页面. 文 ...
- chrome浏览器canvas画图不显示
问题产生在学习cabvas给画布画图像的时候发现使用IE edge浏览器可以正常显示图像,而chrome则不行,经百度后知道是因为chrome浏览器会先加载javascript代码,之后才加载图片,这 ...
- C# DataTable、实体相互转换
public static T GetEntity<T>(DataTable table) where T : new() { T entity = new T(); foreach (D ...
- MySQL的安装及简单调优
MySQL的安装及调优 1. 安装注意点 ubuntu18的安装方式 sudo apt-get update sudo apt-get install -y mysql-server mysql-cl ...
- 树的计数 Prüfer编码与Cayley公式 学习笔记
最近学习了Prüfer编码与Cayley公式,这两个强力的工具一般用于解决树的计数问题.现在博主只能学到浅层的内容,只会用不会证明. 推荐博客:https://blog.csdn.net/moreja ...
- HTML基础 img标签 做一个图库
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 微信小程序swiper组件实现图片宽度自适应
wxml 代码: <!--pages/swipe/swipe.wxml--> <view> <swiper circular="true" indic ...
- ftp 上传文件时报 cant open output connection for file "ftp://129.28.149.240/shop/web/index.html". Reason: "550 Permission denied.".
原因:没有写入权限 修改权限即可 vsftpd.conf vim /etc/vsftpd.conf write_enable=YES #加入这句
- 190行代码实现mvvm模式
前言 网上讲 vue 原理,mvvm 模式的实现,数据双向绑定的文章一搜一大堆,不管写的谁好谁坏,都是写的自己的理解,我也发一篇文章记录自己的理解,如果对看官有帮助,那也是我莫大的荣幸,不过看完之后, ...