用于遗忘查看:
- python矩阵数据转图片:
import scipy.misc scipy.misc.imsave('1.bmp', train_images[i])
- 版本问题:
DeprecationWarning: `imsave` is deprecated! `imsave` is deprecated in SciPy 1.0.0, and will be removed in 1.2.0. Use ``imageio.imwrite`` instead. scipy.misc.imsave('1.bmp', train_images[i])
- 但目前仍可用
- 报错module ‘scipy.misc’ has no attribute ‘xxx’,可用指令
pip install Pillow
安装pillow可能解决(版本问题除外)
-
range和xrange的区别
-
range([start], stop[, step])
- 返回等差数列(列表形式)。构建等差数列,起start,终stop,公差step。(step 和 start是可选项)
-
xrange([start], stop[, step])
- xrange与range类似,只是返回的是一个"xrange object"对象,而非数组list。
-
xrange则不会直接生成一个list,而是每次调用返回其中的一个值,内存空间使用少,性能较好。(python3.x已取出xrange)
-
-
python中函数 reshape(-1,1)
- reshape(行数,列数)用于更改数据的行列号
- -1是指未设定行数(任意正整数),1是表示1列
-
np.flatnonzero():
- 该函数输入一个矩阵,返回扁平化后矩阵中非零元素的位置(index),如:
x = np.arange(-3, 3) np.flatnonzero(x) # output: # [0, 1, 2, 4, 5]