deep_learning_Function_tensorflow_reshape()
numpy.reshape(a, newshape, order='C')[source],参数`newshape`是啥意思?
根据Numpy文档(https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html#numpy-reshape)的解释:
newshape : int or tuple of ints
The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, **the value is inferred from the length of the array and remaining dimensions**.
大意是说,数组新的shape属性应该要与原来的配套,如果等于-1的话,那么Numpy会根据剩下的维度计算出数组的另外一个shape属性值。
举几个例子或许就清楚了,有一个数组z,它的shape属性是(4, 4)
z = np.array([[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]])
z.shape
(4, 4)
z.reshape(-1)
- z.reshape(-1)
- array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
z.reshape(-1, 1)
也就是说,先前我们不知道z的shape属性是多少,但是想让z变成只有一列,行数不知道多少,通过`z.reshape(-1,1)`,Numpy自动计算出有12行,新的数组shape属性为(16, 1),与原来的(4, 4)配套。
z.reshape(-1,1)
array([[ 1],
[ 2],
[ 3],
[ 4],
[ 5],
[ 6],
[ 7],
[ 8],
[ 9],
[10],
[11],
[12],
[13],
[14],
[15],
[16]])
z.reshape(-1, 2)
newshape等于-1,列数等于2,行数未知,reshape后的shape等于(8, 2)
z.reshape(-1, 2)
array([[ 1, 2],
[ 3, 4],
[ 5, 6],
[ 7, 8],
[ 9, 10],
[11, 12],
[13, 14],
[15, 16]])
同理,只给定行数,newshape等于-1,Numpy也可以自动计算出新数组的列数。
转自:https://blog.csdn.net/qq_38409301/article/details/88559889
deep_learning_Function_tensorflow_reshape()的更多相关文章
随机推荐
- java逆向工程-mybatis-generator
题记:在快速开发的项目中有使用到,这样可以避免冗余工作 声明:参考于https://www.cnblogs.com/smileberry/p/4145872.html 环境:必须先安装maven环境, ...
- log4j日志配置文件
log4j.properties: ### 设置### log4j.rootLogger = debug,stdout,D,E ### 输出信息到控制抬 ### log4j.appender.stdo ...
- 六十一:Flask.Session之flask操作session
1.设置session:使用flask.session就可以操作字典,操作方式和操作字典一样:session['key']=value2.获取session,和获取字典的值一样:session['ke ...
- 在mac下安装fiddler
说明:学习fiddler好久了,一直以来也没形成文档,之前学的一些知识也快忘得差不多了:正好利用假期,把之前学的知识都捡起来,捋一遍,形成文档,供以后使用的时候参考和借鉴 一:下载Mono 因为fid ...
- java最常见的5个错误
1. Null 的过度使用 避免过度使用 null 值是一个最佳实践.例如,更好的做法是让方法返回空的 array 或者 collection 而不是 null 值,因为这样可以防止程序抛出 Null ...
- Apache POI读取Excel
1.pom.xml配置文件 <!-- 配置Apache POI --> <dependency> <groupId>org.apache.poi</group ...
- Python的Multiprocessing多进程实例
最近在拜读RBG大神的faster-rcnn源码时发现他用了多进程去分阶段处理神经网络,原因如下: # ------------------------------------------------ ...
- 使用robotframework做接口测试三——保持登录状态
调用登录接口登录了,其他的接口怎么保持登录状态呢? 首先来看一看,web端或者说客户端是怎么样用cookie/token等保持登录状态的.一般来说,cookie都会在登录接口由服务端返回,而且会是在 ...
- Nginx动态添加模块 平滑升级
已经安装好的Nginx动态添加模块 说明: 已经安装好的Nginx,需要添加一个未被编译安装的模块,需要怎么弄呢? 这里已安装第三方nginx-rtmp-module模块为例 nginx的模块是需要重 ...
- BeanPostProcessor详解
转自: https://www.jianshu.com/p/d26e8ec9c077? BeanPostProcessor也称为Bean后置处理器,它是Spring中定义的接口,在Spring容器的创 ...