Python Forum
Why am I getting a type error?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why am I getting a type error?
#1
This should be simple.

I am using NumPy's ndarray, and taking the shape() of the 1st element like this:X.shape[0]. As expected, this is an integer that evaluates to 100.

When I try to add that to integer literal, I get a type error.
type(X.shape[0])
Out[87]: 
int
type(1+X.shape[0])
Out[88]: 
int
type(X)
Out[89]: 
numpy.ndarray
Error:
Traceback (most recent call last):   File "C:\Users\WB\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2881, in run_code     exec(code_obj, self.user_global_ns, self.user_ns)   File "<ipython-input-86-b745a6cdd684>", line 1, in <module>     ppn.fit(X,y)   File "C:\Users\wb\PycharmProjects\untitled8\Perceptron.py", line 9, in fit     zz=1 + X.shape[0] TypeError: unsupported operand type(s) for +: 'int' and 'tuple'
As you can see from the trace, I should be adding two integers. Why does it think one of them is a tuple?
Reply


Messages In This Thread
Why am I getting a type error? - by WagmoreBarkless - Jan-19-2017, 02:01 AM
RE: Why am I getting a type error? - by Mekire - Jan-19-2017, 02:19 AM
RE: Why am I getting a type error? - by Skaperen - Jan-19-2017, 06:06 AM
RE: Why am I getting a type error? - by Mekire - Jan-19-2017, 02:56 AM
RE: Why am I getting a type error? - by ichabod801 - Jan-19-2017, 10:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  GroupBy - Sum = Error [datetime64 type does not support sum operations] BSDevo 4 2,913 Oct-27-2023, 07:22 PM
Last Post: BSDevo
  Type error in Cross_val_score Vicral 0 1,840 Jul-20-2021, 12:18 PM
Last Post: Vicral
  type error array BrianPA 2 2,430 Jan-17-2021, 01:48 PM
Last Post: BrianPA
  Error binding parameter 0 - probably unsupported type. illmattic 7 10,402 Jul-18-2020, 09:32 PM
Last Post: illmattic
  Error Message: TypeError: unhashable type: 'set' twinpiques 4 19,020 May-22-2019, 02:31 PM
Last Post: twinpiques
  Error:unsupported operand type(s) for ** or pow(): 'list' and 'int' mcgrim 3 18,382 Mar-22-2019, 01:29 PM
Last Post: buran
  Type Error Confusion Oliver 4 14,507 Dec-06-2017, 03:20 PM
Last Post: Oliver
  type error and access violation error pyopengl hsunteik 0 3,341 Nov-04-2017, 04:51 AM
Last Post: hsunteik
  AUCPR of individual features using Random Forest (Error: unhashable Type) melissa 1 3,328 Jul-10-2017, 12:48 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020