array.shape() giving error tuple not callable

2024/11/19 15:27:39

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 ry_pred = np.array(r)print y_pred.shape()

This is the output I get:

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:\Users\app\Documents\Python Scripts\gbc_classifier_test.py", line 93, in <module>print y_pred.shape()
TypeError: 'tuple' object is not callable

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.

Answer

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

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

https://en.xdnf.cn/q/26423.html

Related Q&A

Python unittest - Ran 0 tests in 0.000s

So I want to do this code Kata for practice. I want to implement the kata with tdd in separate files:The algorithm:# stringcalculator.py def Add(string):return 1and the tests:# stringcalculator.spec.…

How and where does py.test find fixtures

Where and how does py.test look for fixtures? I have the same code in 2 files in the same folder. When I delete conftest.py, cmdopt cannot be found running test_conf.py (also in same fo…

Python match a string with regex [duplicate]

This question already has answers here:What exactly do "u" and "r" string prefixes do, and what are raw string literals?(7 answers)What exactly is a "raw string regex" an…

What are the consequences of disabling gossip, mingle and heartbeat for celery workers?

What are the implications of disabling gossip, mingle, and heartbeat on my celery workers?In order to reduce the number of messages sent to CloudAMQP to stay within the free plan, I decided to follow …

How to determine if an exception was raised once youre in the finally block?

Is it possible to tell if there was an exception once youre in the finally clause? Something like:try:funky code finally:if ???:print(the funky code raised)Im looking to make something like this m…

How to use re match objects in a list comprehension

I have a function to pick out lumps from a list of strings and return them as another list:def filterPick(lines,regex):result = []for l in lines:match = re.search(regex,l)if match:result += [match.grou…

How do I run pip on python for windows? [duplicate]

This question already has answers here:Why does "pip install" inside Python raise a SyntaxError?(6 answers)Closed 8 years ago.Ive just installed python 3.5, ran Python 3.5 (32-bit) and typed…

Select certain rows by index of another DataFrame

I have a DataFrame and I would select only rows that contain index value into df1.index. for Example: In [96]: df Out[96]:A B C D 1 1 4 9 1 2 4 5 0 2 3 5 5 1 0 22 1 3 9 6and these ind…

Execute .sql schema in psycopg2 in Python

I have a PostgreSQL schema stored in .sql file. It looks something like:CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY,facebook_id TEXT NOT NULL,name TEXT NOT NULL,access_token TEXT,created I…

AttributeError: module html.parser has no attribute HTMLParseError

This is the hints,how can I resolve it? I use Python 3.5.1 created a virtual envirement by virtualenv The source code works well on my friends computer machineError: Traceback (most recent call last):…