array.shape() 给出错误元组不可调用 [英] array.shape() giving error tuple not callable

查看:29
本文介绍了array.shape() 给出错误元组不可调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 results 的 2D numpy 数组,它包含自己的数据数组,我想进入其中并使用每个列表:

I have a 2D numpy array called results, which contains its own array of data, and I want to go into it and use each list:

for r in results:
    print "r:"
    print r
    y_pred = np.array(r)
    print y_pred.shape()

这是我得到的输出:

r:
[ 25.  25.  25.  25.  25.  25.  26.  26.  26.  26.  26.  22.  27.  27.  42.
  23.  23.  23.  28.  28.  28.  44.  29.  29.  30.  30.  30.  18.  18.  18.
  19.  30.  17.  17.  17.  17.   2.  19.   2.  17.  17.  17.  17.  17.  17.
   4.  17.  17.  41.   7.  17.  19.  19.  19.  10.  32.   4.  19.  34.  19.
  34.  34.  34.  34.  34.  34.  20.  20.  20.  36.  36.  36.   4.  36.  36.
  22.  22.  22.  22.  22.  22.  23.  23.  23.  27.  27.  27.  24.  39.  39.
  10.  10.  10.   6.  10.  10.  11.  11.  11.  11.  11.  11.  12.  12.  12.
  12.  12.  12.  13.  13.  13.  14.  14.  14.  15.  15.  15.   1.  17.   1.
   2.   2.   2.   2.   2.   2.   2.   2.   2.   2.   2.   2.   2.   2.   2.
  19.  19.  19.   2.   2.   4.   3.   3.   3.   4.   4.   4.   4.   4.   4.
   4.  19.   4.   4.   4.  17.   5.   5.   5.   6.   6.   6.   6.   6.   6.
   7.   7.   7.   7.   7.   7.   8.   8.   8.   8.   8.   8.   9.   9.   9.
  23.  38.  38.  34.  34.  10.  17.  17.  26.   0.  42.   0.  18.  32.  32.
   0.   0.  21.  38.  38.  38.  27.  27.  27.   0.   0.   0.  34.   2.   2.
   0.  26.  26.  36.   0.  36.  36.  36.  23.   0.  27.  38.  25.  25.  25.
  26.  26.  26.   0.  15.  15.  32.  38.  38.   0.  32.  32.  32.  41.  32.
   7.  34.  32.  42.  34.  34.  36.  36.  25.  32.  32.  32.  36.  17.   8.
  32.  17.  38.   3.   3.   3.  18.  18.  18.   0.   1.   1.  34.   1.   1.
  34.  17.  17.  34.  34.  34.  34.  34.  34.  17.  17.  17.  24.   2.  32.
   2.   2.   2.   0.   2.   2.   0.  34.  34.   0.   1.   1.  38.  23.  38.]
Traceback (most recent call last):
  File "C:UsersappDocumentsPython Scriptsgbc_classifier_test.py", line 93, in <module>
    print y_pred.shape()
TypeError: 'tuple' object is not callable

我不明白为什么 y_pred 不是常规数组以及为什么将其视为元组,我已使用 r 将其分配为数组.

I don't understand why y_pred is not a regular array and why it's being considered a tuple, I've assigned it to be an array using r.

推荐答案

shape 只是一个属性,而不是一个方法.只需使用 y_pred.shape(无括号).

shape is just an attribute, not a method. Just use y_pred.shape (no parentheses).

(错误消息不是告诉你 y_pred 是一个元组,而是告诉你 y_pred.shape 是一个元组.)

(The error message isn't telling you that y_pred is a tuple, it's telling you that y_pred.shape is a tuple.)

这篇关于array.shape() 给出错误元组不可调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆