0

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?

6
  • Why are you using numpy.coordinates? just use coordinates. Commented Jun 27, 2012 at 18:13
  • Will that recognize a numpy array? I assumed there needed to be some way to denote a numpy array. Commented Jun 27, 2012 at 18:15
  • Python is a dynamic typed language, variable names don't have to know anything about the objects they point to, so as long as coordinates is a numpy array, then that's what your new variable would be. Commented Jun 27, 2012 at 18:17
  • Thank you for your explanation and patience. I appreciate it. I wish I could have given you points for your answer. Commented Jun 27, 2012 at 18:19
  • 1
    No problem, you should also learn about Namespaces or variable scopes in Python. Commented Jun 27, 2012 at 18:22

1 Answer 1

2
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)

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the annotations and answer!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.