多次调用和检索numpy数组

时间:2017-04-23 05:03:51

标签: python arrays numpy

我的代码是这样的:

def something():
   """this function will call the `get_array` multiple times until the
      end of the array and is fixed (cannot change this function)"""
   #skip some functions and initialization there
   #only used to get the result of `get_array`
   a.get_array()

在另一个文件中:

class a:
    def __init__(self, count=-1):
        self.count = count

    def cal_array(self, parameters):
        """calculate array"""
        return array

    def get_array(self, parameters):
        if self.count == -1:
            self.cal_array(parameters)
            # some methods to store array there
        else:
            self.count += 1
            return array[self.count,:]

我想知道是否有办法计算一次numpy数组并将其保存以备将来使用(从另一个函数调用)。

我知道我可以将numpy数组保存到磁盘或使用全局字典保存数组,但我想知道是否有更有效的方法来执行此操作。

0 个答案:

没有答案