[英]Convert 2D array into RGB image in a loop in Python
I want to convert a 2-dimensional array into an image in python using scipy.misc. 我想使用scipy.misc将二维数组转换为python中的图像。 Following is an example what I want to achieve 以下是我要实现的示例
import numpy as np
from scipy.misc import toimage, imsave
L = 20 # one side of lattice
N = L*L # number of sites in the lattice
xs = np.zeros((L,L), float)
x = []
for n in range(100):
for i in range(L):
for j in range(L):
xs[i,j] = np.random.uniform(0.1, 0.9)
x.append(xs)
In this code, for each n value I get a 2D array of xs which I am storing in list x. 在这段代码中,对于每个n值,我得到一个xs的二维数组,并将其存储在列表x中。 Instead of storing 2D array xs for each n in x, how can I convert it to an Colour RGB Image, where each value of x between 0.1 and 0.9 would be denoted by different colours ? 而不是为x中的每个n存储2D数组xs,我如何将其转换为彩色RGB图像,其中x的值在0.1到0.9之间将用不同的颜色表示?
import numpy as np
import matplotlib.pyplot as plt
L = 20 # one side of lattice
N = L*L # number of sites in the lattice
xs = np.zeros((L, L), float)
for n in range(100):
for i in range(L):
for j in range(L):
xs[i,j] = np.random.uniform(0.1, 0.9)
plt.imshow(xs)
plt.colorbar()
plt.savefig('temp.png')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.