简体   繁体   English

不能将序列乘以'float'类型的非整数错误?

[英]can't multiply sequence by non-int of type 'float' error?

I am trying to do a simple calculation (which later will be done on an array) and getting the aforementioned error. 我试图做一个简单的计算(稍后将在数组上完成)并得到上述错误。

can't multiply sequence by non-int of type 'float' 无法将序列乘以'float'类型的非整数

8.99*[-(math.log(1-0.5))**(1/2.87)]

The square brackets turn the result of -(math.log(1-0.5))**(1/2.87) into a list with a single element. 方括号将-(math.log(1-0.5))**(1/2.87)转换为带有单个元素的列表。 The error message is due to the "multiplication" of the list by 8.99. 该错误信息是由于列表与8.99的“相乘”。 The * operator when applied to a list means to repeat the list elements that many times and to create a new list. 当将*运算符应用于列表时,它意味着多次重复列表元素并创建一个新列表。 eg 5 * [1] becomes [1, 1, 1, 1, 1] . 例如5 * [1]变为[1, 1, 1, 1, 1] Python is complaining that you can't repeat the elements 8.99 times. Python抱怨您不能重复元素8.99次。

You can just remove the square brackets to get a valid answer 您只需删除方括号即可获得有效答案

8.99 * -(math.log(1 - 0.5)) ** (1 / 2.87)

You're trying to multiply a list (denoted by square brackets) as a number. 您正在尝试将列表(由方括号表示)乘以一个数字。 Try 尝试

8.99*(-(math.log(1-0.5))**(1/2.87)) instead. 8.99*(-(math.log(1-0.5))**(1/2.87))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM