Python 生成 -1~1 之间的随机数矩阵方法
1. 使用函数 np.random.random
由于 np.random.random() 默认生成 0~1 之间的小数,因此需要转换一下

如生成 3*3 的 -1~1 之间的随机数矩阵
-1 + 2*np.random.random((3,3))
# -*- coding:utf-8 -*-
import matplotlib.pyplot as plt
import pylab
import cv2
import numpy as np
img = plt.imread("1.png") #在这里读取图片
#plt.imshow(img) #显示读取的图片
#pylab.show()
print "start processing..."
for i in range(1,200):
# fil = np.random.randint(0, 10, size=[3, 3])
fil = -1 + 2*np.random.random((3,3))
res = cv2.filter2D(img,-1,fil) #使用opencv的卷积函数
# plt.imshow(res) #显示卷积后的图片
pic_name = str(i) + ".png"
# plt.imsave(pic_name, res)
# plt.imsave("res.jpg",res)
# pylab.show()
print "complete!" 相关推荐
jessieHJ 2020-05-31
xinhao 2020-05-28
czsay 2020-05-25
Lexan 2020-04-15
idning 2020-03-08
明天你好 2020-01-28
georgeandgeorge 2019-12-28
wordmhg 2019-10-26
小方哥哥 2019-06-02
chunjiekid 2019-03-21
聪聪李 2020-06-13
qscool 2020-05-06
xiechao000 2020-04-21
IBMRational 2020-03-07
zuihaobushi 2020-02-24
Canethui 2020-02-22
蜗牛慢爬的李成广 2020-02-02
yfisaboy 2020-01-19
风吹夏天 2020-01-10