简体   繁体   中英

defining an already exisiting numpy array within a class

I am creating an object in python. I have a numpy array from an H5 file that I would like to define within it. The numpy array is coordinates . I was poking around online and found tons of information about creating numpy arrays, or creating objects in numpy arrays.. but I can't find anything on defining an already made numpy array inside an object.

class Node(object):
    def __init__(self, globalIndex, coordinates):

        #Useful things to record
        self.globalIndex = globalIndex
        self.coordinates = numpy.coordinates

        #Dictionaries to be used
        self.localIndices ={}
        self.GhostLayer = {}

My question: is there a specific way to define my numpy array within this class? If not (the fact that I couldn't find anything about it makes me think that it can't be done), how else could I import a numpy array?

class Node(object):
    def __init__(self, globalIndex, coordinates):

        #Useful things to record
        self.globalIndex = globalIndex
        self.coordinates = coordinates # now self.coordinates is just another name for your array

Assuming n = Node(some_index, numpy_coordinate_array_name)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM