'numpy.float64' object does not support item assignment alignment sequences

Question:

I am developing a program to calculate the sp scores of aligned sequences from the Percent Identity Matrix obtained on Clustal Omega.

I have problems with element casting in python. I’m trying to store the values read from a text file in an array of floats.

The code is:

filename_matrix = '1-1-proteinas.pim'
infile = open(filename_matrix, 'r')
lines = []
num_sequences = 10
matrix = np.array((num_sequences,num_sequences), dtype = float)
j = 0
for l in infile:
    if l[0] != '#':
        words = l.split()
        if len(words) == num_sequences + 2:
            for i in range(2,len(words)):
                val = np.float64(words[i])
                matrix[j][i-2] = val
            j = j + 1

The data appearence is something like:


#
#
#  Percent Identity  Matrix - created by Clustal2.1 
#
#

     1: WDD56501.1  100.00   83.15   82.87   18.78   26.27   25.85   26.89   27.22   25.00   24.59
     2: WDD56502.1   83.15  100.00   99.45   20.66   28.39   27.97   28.30   27.78   26.64   26.23
     3: WDD44798.1   82.87   99.45  100.00   20.66   28.39   27.97   28.30   27.78   26.64   26.23
     4: WDD56503.1   18.78   20.66   20.66  100.00   25.44   25.88   27.14   25.93   24.37   23.53
     5: WDD56500.1   26.27   28.39   28.39   25.44  100.00   98.45   98.21   70.27   64.34   61.63
     6: WDD56504.1   25.85   27.97   27.97   25.88   98.45  100.00   99.11   69.73   64.73   62.02
     7: WDD44799.1   26.89   28.30   28.30   27.14   98.21   99.11  100.00   69.73   69.64   67.41
     8: WDD56497.1   27.22   27.78   27.78   25.93   70.27   69.73   69.73  100.00   71.12   69.52
     9: WDD56499.1   25.00   26.64   26.64   24.37   64.34   64.73   69.64   71.12  100.00   87.36
    10: WDD56498.1   24.59   26.23   26.23   23.53   61.63   62.02   67.41   69.52   87.36  100.00

And the error I have obtained is:

Traceback (most recent call last):

  File "C:Usersuserminiconda3envstfglibsite-packagesspyder_kernelscustomizespyderpdb.py", line 889, in run
    super(SpyderPdb, self).run(cmd, globals, locals)

  File "C:Usersuserminiconda3envstfglibbdb.py", line 580, in run
    exec(cmd, globals, locals)

  File "c:usersuseronedriveescritoriocuarto infbioinfp2puntuaciones.py", line 21, in <module>
    matrix[j][i-2] = val

TypeError: 'numpy.float64' object does not support item assignment
Asked By: cs1234

||

Answers:

Could the culprit be these two lines?

num_sequences = 10
matrix = np.array((num_sequences,num_sequences), dtype = float)

It makes matrix = array([10., 10.]) and not an matrix of dimension (10,10).
The matrix dimension is just (2,1).

Answered By: Mathpdegeek497
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.