成功解决ret = ret / rcountTypeError: unsupported operand type(s) for /: ‘str‘ and ‘int‘

简介: 成功解决ret = ret / rcountTypeError: unsupported operand type(s) for /: ‘str‘ and ‘int‘


目录

解决问题

解决思路

解决方法


解决问题

   boxplot(array)

 File "E:\Program Files\Python\Python36\lib\site-packages\matplotlib\pyplot.py", line 2848, in boxplot

   zorder=zorder, data=data)

 File "E:\Program Files\Python\Python36\lib\site-packages\matplotlib\__init__.py", line 1855, in inner

   return func(ax, *args, **kwargs)

 File "E:\Program Files\Python\Python36\lib\site-packages\matplotlib\axes\_axes.py", line 3557, in boxplot

   labels=labels, autorange=autorange)

 File "E:\Program Files\Python\Python36\lib\site-packages\matplotlib\cbook\__init__.py", line 1841, in boxplot_stats

   stats['mean'] = np.mean(x)

 File "<__array_function__ internals>", line 6, in mean

 File "E:\Program Files\Python\Python36\lib\site-packages\numpy\core\fromnumeric.py", line 3373, in mean

   out=out, **kwargs)

 File "E:\Program Files\Python\Python36\lib\site-packages\numpy\core\_methods.py", line 172, in _mean

   ret = ret / rcount

TypeError: unsupported operand type(s) for /: 'str' and 'int'

解决思路

类型错误:不支持/:“str”和“int”的操作数类型

解决方法

通过print(array)发现,array中存在str类型数据,所以,要讲str类型数据去掉或者转为int型数据即可!

1. array [[2.1909676502373716 2.607015388816513 1.3860962260762568 ...
2.   -1.1294268713572033 2.5030404172865484 '1']
3.  [2.1833913365652493 2.607015388816513 1.3760805967854473 ...
4.   -0.7176317548954712 2.4492909440768904 '1']
5.  [2.172026866057066 2.607015388816513 1.3760805967854473 ...
6.   -0.6735108495602856 2.180543578028602 '1']
7.  ...
8.  [2.172026866057066 2.607015388816513 1.3760805967854473 ...
9.   -0.6735108495602856 1.9547957905480406 '1']
10.  [2.1833913365652493 2.607015388816513 1.3760805967854473 ...
11.   -0.6735108495602856 2.03004505304156 '1']
12.  [2.172026866057066 2.607015388816513 1.3760805967854473 ...
13.   -0.6735108495602856 1.9977953691157657 '1']]

哈哈,大功告成!

文章知识点与官方知识档案匹配,可进一步学习相关知识

Python入门技能树绘图库Matplotlib风格和样式81260 人正在系统学习中


相关文章
|
10月前
YOLO V5出现RuntimeError: result type Float can‘t be cast to the desired output type long int解决方法
YOLO V5出现RuntimeError: result type Float can‘t be cast to the desired output type long int解决方法
540 0
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
370 0
|
Python
Python类型转换的四个函数int()、float()、str()、bool()
Python类型转换的四个函数int()、float()、str()、bool()自制脑图 将一个类型的对象转换为其他对象类型转换不是改变对象本身的类型,而是根据当前对象的值创建一个新对象。
210 0
Python类型转换的四个函数int()、float()、str()、bool()
|
Python
【hacker的错误集】TypeError: can‘t multiply sequence by non-int of type ‘str‘
我比较喜欢通过单词的意思来分析报错 TypeError类型错误 multiply乘 sequence 序列 通过分析可以得出报错意思大概是类型错误:无法将序列与字符串类型的非整数相乘
329 0
【hacker的错误集】TypeError: can‘t multiply sequence by non-int of type ‘str‘
|
存储
TypeError: can only concatenate str (not “int“) to str
TypeError: can only concatenate str (not “int“) to str
321 0
TypeError: can only concatenate str (not “int“) to str
|
JSON 数据格式 Python
python编程:json indent can't multiply sequence by non-int of type 'str'
python编程:json indent can't multiply sequence by non-int of type 'str'
122 0
成功解决lightgbm.basic.LightGBMError: Parameter max_depth should be of type int, got “0.02“
成功解决lightgbm.basic.LightGBMError: Parameter max_depth should be of type int, got “0.02“
TypeError: unsupported operand type(s) for -=: &#39;Retry&#39; and &#39;int&#39;
TypeError: unsupported operand type(s) for -=: &#39;Retry&#39; and &#39;int&#39;
180 0