close

[Solved] Type: ‘numpy.float64’ object does not support item assignment

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Type: ‘numpy.float64’ object does not support item assignment in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Type: ‘numpy.float64’ object does not support item assignment Error Occurs?

Today I get the following error Type: ‘numpy.float64’ object does not support item assignment in python.

How To Solve Type: ‘numpy.float64’ object does not support item assignment Error ?

  1. How To Solve Type: 'numpy.float64' object does not support item assignment Error ?

    To Solve Type: 'numpy.float64' object does not support item assignment Error there is no element in array is bigger than 1,So you cannot assign 1 to predictions[predictions>1],you can use ' predictions>1 ' before your assignment.

  2. Type: 'numpy.float64' object does not support item assignment

    To Solve Type: 'numpy.float64' object does not support item assignment Error there is no element in array is bigger than 1,So you cannot assign 1 to predictions[predictions>1],you can use ' predictions>1 ' before your assignment.

Solution 1

Try this testing code and pay attention to np.array([1,2,3], dtype=np.float64). It seems self.svm.decision_function(vectors) returns 1d array instead of 2d. If you replace [1,2,3] to [[1,2,3], [4,5,6]] everything will be ok.

import numpy as np
predictions = np.array([1,2,3], dtype=np.float64)
predictions = np.transpose(predictions)[0]
predictions = predictions / 2 + 0.5
predictions[predictions > 1] = 1
predictions[predictions < 0] = 0

Output:

Traceback (most recent call last):
  File "D:\temp\test.py", line 7, in <module>
    predictions[predictions > 1] = 1
TypeError: 'numpy.float64' object does not support item assignment

So, what your vectors are?

Solution 2

  >>> predictions = np.array([1,2,3], dtype=np.float64)
    >>> predictions
    array([1., 2., 3.])
    >>> predictions = np.transpose(predictions)[0]
    >>> predictions
    1.0
    >>> predictions = predictions / 2 + 0.5
    >>> predictions
    1.0
    >>> predictions>1
    False

there is no element in array is bigger than 1,So you cannot assign 1 to predictions[predictions>1],you can use ‘ predictions>1 ‘ before your assignment.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read