TypeError:图像数据无法转换为float [英] TypeError: Image data can not convert to float
问题描述
我想创建一个16位图像。所以我写了一个代码。
I want to create an 16 bit image. So i have written a code.
import skimage
import random
from random import randint
xrow=raw_input("Enter the number of rows to be present in image.=>")
row=int(xrow)
ycolumn=raw_input("Enter the number of columns to be present in image.=>")
column=int(ycolumn)
A={}
for x in xrange(1,row):
for y in xrange(1,column):
a=randint(0,65535)
A[x,y]=a
imshow(A)
但每当我运行此代码时,我都会收到错误,显示TypeError:图像数据无法转换为浮动。是否有任何解决方案。
But whenever i run this code, i get an error displaying "TypeError: Image data can not convert to float".Is there any solution for this.
我为我的写作中的错误道歉,因为这是我上面提到的第一个问题。
I apologies for the mistakes in my write up, as this is my first question which i have asked above.
推荐答案
这个问题首先出现在谷歌搜索此类型错误中,但没有关于错误原因的一般答案。海报的独特问题是使用不适当的对象类型作为 plt.imshow()
的主要参数。更一般的答案是 plt.imshow()
想要一个浮点数组,如果你没有指定 float
,numpy,pandas或其他任何可能在某个地方推断出不同的数据类型。您可以通过为 dtype指定
参数是对象的构造函数。 float
来避免这种情况.dtype
This question comes up first in the Google search for this type error, but does not have a general answer about the cause of the error. The poster's unique problem was the use of an inappropriate object type as the main argument for plt.imshow()
. A more general answer is that plt.imshow()
wants an array of floats and if you don't specify a float
, numpy, pandas, or whatever else, might infer a different data type somewhere along the line. You can avoid this by specifying a float
for the dtype
argument is the constructor of the object.
请参阅 Numpy文档这里。
请参阅这里有Pandas文档
这篇关于TypeError:图像数据无法转换为float的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!