Python Can't Multiply Sequence by Non-Int of Type 'Float'

I am trying to evaluate a formula, np is numpy:

Ds = pow(10,5)
D = np.linspace(0, pow(10,6), 100)
alpha=1.44
beta=0.44
A=alpha*(D/Ds)
L=1.65
buf2=L/4.343
buf=pow(-(alpha*[D/Ds]),beta)
value=exp(buf)

and then I will plot this data but I get:

buf=pow(-(alpha*[D/Ds]),beta)
TypeError: can't multiply sequence by non-int of type 'float'

How can I overcome this?

1

1 Answer

Change:

buf=pow(-(alpha*[D/Ds]),beta)

to:

buf=pow(-(alpha*(D/Ds)),beta)

This:

[D/Ds]

gives you list with one element.

But this:

alpha * (D/Ds)

computes the divisions before the multiplication with alpha.

You can multiply a list by an integer:

>>> [1] * 4
[1, 1, 1, 1]

but not by a float:

[1] * 4.0
TypeError: can't multiply sequence by non-int of type 'float'

since you cannot have partial elements in a list.

Parenthesis can be used for grouping in the mathematical calculations:

>>> (1 + 2) * 4
12
7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest