What runs on Jupiter's laptop is not working on Python. (NameError: name 'XXX' is not defined)

Asked 2 years ago, Updated 2 years ago, 91 views

class Tensor:

    def __init__(self, data, shape):
        self.data = data
        self.shape = shape
        self.tensor = shape_data(self.data,self.shape)  # <-- *

    def shape_data(self,data,shape):
        temp1=[]
        temp2=[]
        shape.reverse()
        .....

I wrote the coding in this way, but it's not a problem on Jupiter laptop When I moved it to Python IDLE, the part marked with * was

There's an error like this. I've declared all the names of functions, but I can't figure out why they're not defined. Even if the function comes in order first, it's meaningless and doesn't solve it.

I don't know why there is a difference between Jupiter laptop and Python.

python jupyter-notebook nameerror

2022-09-22 13:06

1 Answers

self.tensor = self.shape_data(self.data,self.shape)

The method of the class is invoked with self..

If it worked well in Jupiter, it is estimated that the cell that defined shape_data as a general function has already been run and knew the function shape_data.


2022-09-22 13:06

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.