Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 *** NameError: name '' is not defined
#1
I want to compare the first column of an array with all the other columns and then break the function if they are all the same.

Outside the function, this code works.

import numpy as np
comms = np.array([[3, 3, 2, 2],
       [3, 2, 0, 3],
       [2, 2, 0, 4],
       [0, 4, 0, 4],
       [1, 0, 0, 2]])

M = comms.shape[0]
all((comms[i, : ] == comms[0, : ]).all() for i in range(M))
However, evaluated inside the function, it fails

def varinfo(comms):
    M = comms.shape[0]   
    
    return all((comms[i, : ] == comms[0, : ]).all() for i in range(M))
This is very strange. Could someone help?
ichabod801 wrote Apr-08-2019, 01:17 PM:
Use Python tags (the Python logo button) for posting code, not icode tags ([] button) for multiline code. The icode tags are for inline code.
Quote
#2
I'm not getting an error running either batch of code. For the second one, you are defining comms and passing it to varinfo as a parameter, right? This is how I'm running the second batch of code:

import numpy as np
comms = np.array([[3, 3, 2, 2],
       [3, 2, 0, 3],
       [2, 2, 0, 4],
       [0, 4, 0, 4],
       [1, 0, 0, 2]])

def varinfo(comms):
    M = comms.shape[0]

    return all((comms[i, : ] == comms[0, : ]).all() for i in range(M))

varinfo(comms)
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  NameError 'odometer' not defined rfernandez15 1 92 Nov-25-2019, 09:57 PM
Last Post: ichabod801
  NameError: NameError: global name 'BPLInstruction' is not defined colt 7 349 Oct-27-2019, 07:49 AM
Last Post: Larz60+
  Function Annotation got NameError: name 'xxx' is not defined Lance 6 317 Oct-23-2019, 03:13 AM
Last Post: Lance
  NameError: name 'processing' is not defined soli004 2 434 Sep-07-2019, 11:57 AM
Last Post: soli004
  NameError: name 'display' is not defined when running code on power bi beginner1 2 1,703 Jul-24-2019, 11:03 AM
Last Post: beginner1
  tkinter - "NameError: name 'frame' is not defined" Mocap 3 1,122 Jul-21-2019, 09:03 PM
Last Post: Yoriz
  [split] NameError: name 'lo' is not defined when using input ? Cedmo 2 439 Jul-05-2019, 09:39 PM
Last Post: Cedmo
  NameError: name 'lst' is not defined Jmekubo 2 835 Apr-27-2019, 12:34 PM
Last Post: Jmekubo
  help (variables) - NameError: name 'Payment' is not defined? Vqlk 5 585 Feb-27-2019, 04:57 PM
Last Post: buran
  NameError: name 'd' is not defined synthex 1 838 Feb-23-2019, 12:35 PM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)