【问题标题】:'numpy.float64' object does not support item assignment alignment sequences\'numpy.float64\' 对象不支持项目分配对齐序列
【发布时间】:2023-02-26 18:36:18
【问题描述】:

我正在开发一个程序来计算从 Clustal Omega 上获得的百分比同一性矩阵比对序列的 sp 分数。

我在 python 中进行元素转换时遇到问题。我正在尝试将从文本文件中读取的值存储在浮点数组中。

代码是:

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

数据外观类似于:


#
#
#  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

我得到的错误是:

Traceback (most recent call last):

  File "C:\Users\user\miniconda3\envs\tfg\lib\site-packages\spyder_kernels\customize\spyderpdb.py", line 889, in run
    super(SpyderPdb, self).run(cmd, globals, locals)

  File "C:\Users\user\miniconda3\envs\tfg\lib\bdb.py", line 580, in run
    exec(cmd, globals, locals)

  File "c:\users\user\onedrive\escritorio\cuarto inf\bioinf\p2\puntuaciones.py", line 21, in <module>
    matrix[j][i-2] = val

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

【问题讨论】:

    标签: python casting alignment clustal


    【解决方案1】:

    罪魁祸首可能是这两行吗?

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

    它生成matrix = array([10., 10.]) 而不是维度为(10,10) 的矩阵。 matrix维度就是(2,1)

    【讨论】:

      猜你喜欢
      • 2019-01-03
      • 1970-01-01
      • 2021-02-14
      • 2015-03-09
      • 2016-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多