Marx Babu
Marx Babu

Reputation: 760

Python error 'numpy.float64' object cannot be interpreted as an integer

I'm using Python3.x. The bricks = [] the data is dataframe single element array which contains number and some negative numbers

for delta in data:
    if delta > 0:
        bricks.extend([1] * delta)
    else:
        bricks.extend([-1] * abs(delta))

The above code throws error, without affecting the outcome how to correct the code which will run without errors

The error here is:

bricks.extend([1] * delta) TypeError: 'numpy.float64' object cannot be interpreted as an integer

Note :Community, before giving negative numbers, marked as duplicate provide a solution and then mark as you wish.

Upvotes: 1

Views: 2629

Answers (1)

Jutorres
Jutorres

Reputation: 126

I think you should try

    bricks.extend([1. * delta])

Considering that your "delta" is a simple value(numpyFloat or something like that) and you want to extend the list with a list of 1 value.

Upvotes: 1

Related Questions