Python Forum
*** NameError: name '' is not defined
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?
Reply
#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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I'm getting a NameError: ...not defined. vonArre 2 264 Mar-24-2024, 10:25 PM
Last Post: vonArre
  Getting NameError for a function that is defined JonWayn 2 1,095 Dec-11-2022, 01:53 PM
Last Post: JonWayn
Question Help with function - encryption - messages - NameError: name 'message' is not defined MrKnd94 4 2,876 Nov-11-2022, 09:03 PM
Last Post: deanhystad
  [split] NameError: name 'csvwriter' is not defined. Did you mean: 'writer'? cathy12 4 3,303 Sep-01-2022, 07:41 PM
Last Post: deanhystad
  NameError: name ‘app_ctrl’ is not defined 3lnyn0 0 1,507 Jul-04-2022, 08:08 PM
Last Post: 3lnyn0
  NameError: name 'hash_value_x_t' is not defined Anldra12 5 1,913 May-13-2022, 03:37 PM
Last Post: deanhystad
  NameError: name 'cross_validation' is not defined tmhsa 6 13,336 Jan-17-2022, 09:53 PM
Last Post: TropicalHeat
  NameError: name “x” is not defined ... even though x is defined campjaybellson 7 14,941 Oct-20-2021, 05:39 PM
Last Post: deanhystad
  NameError: name 'Particle' is not defined in Pygame drunkenneo 4 3,371 Aug-15-2021, 06:12 PM
Last Post: bowlofred
  NameError: name 'u1' is not defined (on parser code Python) Melcu54 1 2,877 Jul-26-2021, 04:36 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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