在类中定义已经存在的numpy数组

时间:2012-06-27 18:06:31

标签: python arrays class numpy

我在python中创建一个对象。我有一个H5文件中的numpy数组,我想在其中定义。 numpy数组是coordinates。我在网上闲逛,发现了大量有关创建numpy数组或在numpy数组中创建对象的信息..但是我找不到任何关于在对象中定义已经制作的numpy数组的信息。

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 = {}

我的问题:有没有一种特定的方法在这个类中定义我的numpy数组?如果不是(我无法找到任何关于它的事实让我觉得它无法完成),我怎么能导入一个numpy数组呢?

1 个答案:

答案 0 :(得分: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

假设n = Node(some_index, numpy_coordinate_array_name)

相关问题