avi
avi

Reputation: 95

cannot be safely interpreted as an integer in python

I am trying with with this code a=np.logspace(-1,np.log10(10,),11.)[::-1] but getting error as below TypeError: object of type <class 'float'> cannot be safely interpreted as an integer.

Upvotes: 0

Views: 102

Answers (2)

ForceBru
ForceBru

Reputation: 44838

According to the documentation, the third argument to np.logspace is the "Number of samples to generate". In your code, np.logspace(-1,np.log10(10,),11.) the third argument is 11., which is a floating-point number, but an integer is required, like 11, without the decimal point.

Upvotes: 1

ShadowRanger
ShadowRanger

Reputation: 155418

You passed 11. as num, which is supposed to be an integer. 11. is a float literal; remove the . to make it 11, an int literal.

Upvotes: 3

Related Questions