python - 有没有办法用普通列表实现 numpy 的方法?
问题描述
我正在尝试实现一个将大 numpy 数组分解为n 个数组列表的类。问题是,由于空间的原因,很难使用非常大的数组,所以我试图做的就是将它们拆分成列表。因为列表在存储方式上更加灵活。
我目前拥有的是一个已经在做部分技巧的类:
class Array_list:
data = list()
sliced = 0
def __init__(self, new_list = None):
self.data = [new_list] if ( type(new_list) == type(list()) ) else list()
self.sliced = 0
def __getitem__(self, index):
self.data[index // self.sliced][index % self.sliced]
def __str__(self):
return self.data.__str__()
def __repr__(self):
return self.data.__repr__()
def slice(self, n):
concat, output = [], []
while (len(self.data) > 0):
size = 0
while ((size < n) and (len(self.data) > 0)):
if (len(self.data[0]) <= (n - size)):
concat.append(self.data[0])
size += len(self.data[0])
del self.data[0]
else:
concat.append(self.data[0][:(n - size)])
size += len(self.data[0])
self.data.insert(1, self.data[0][(n - size):])
del self.data[0]
output.append(np.concatenate(concat))
concat = list()
self.data = output
self.sliced = n
我坚持的部分是处理 numpy 的功能,主要是列提取器和求和,如下所示:
arr = np.array([ [0, 1, 2],
[9, 8, 7] ])
print(arr[:, 0])
print(arr[:, [1, 0]])
print(arr + 5)
我需要在我的主代码中使用它们,但我也遇到了数组太大的问题。有人对我可以做什么或搜索什么有任何提示吗?
PS:当谈到 Python 时,我是一个初学者,这也是我在 Stack Overflow 上的第一个问题,所以非常欢迎任何关于任何事情的反馈
解决方案
推荐阅读
- javascript - 如何使 Vuetify 轮播图像响应,尤其是在移动屏幕上?
- r - 如何在ggplot上绘制不同的线?“组=变量”不起作用?
- ios - 具有一个视图控制器水平方向的垂直方向应用程序。如何在故事板上进行设计?
- javascript - 需要在选择日期范围名称时设置默认日期
- visual-studio-code - 减小 VSCode 中工具提示的大小
- python - 如何在带有熊猫的标题行中应用 Filer
- javascript - 将方法分配给变量时使用箭头函数声明方法和函数()之间的区别?
- rust - 将一种类型映射到 rust 中的另一种类型
- java - 无法提取结果集;SQL [不适用];嵌套异常是 org.hibernate.exception.SQLGrammarException: could notextract ResultSet delete not working
- c++ - 在函数中去掉 BIGNUM BN_bn2mpi