python - 重塑/填充 Numpy 数组 - Python
问题描述
我有一个像这样的多个 numpy 数组:
[1, 5, 0, 0]
[2, 1, 3, 1]
[1, 3, 4, 1]
我所有的数组都有不同的值和形状。
我想编写一个函数,将我所有的数组填充到相同的形状。
目前,我正在做这样的事情(在 for 循环内):
width = int(7000 - size[0])
height = int(7000 - size[1])
data = np.pad(data, (width, height), 'constant', constant_values=(0,0))
其中 data 是正在编辑的数组,而 7000x7000 是我最大的数组。
这给了我一个 MemoryError。
解决方案
推荐阅读
- sql - 如何根据 sqlite 中的另一列为每个组选择前 3 名?
- node.js - Dialog api v2 - 获取应用程序默认凭据时出现意外错误:无法加载默认凭据
- oracle - Oracle MERGE 语句是否在提交完成之前返回
- r - R:使用观察次数删除变量
- tfs - 下载 TFS 流程模板
- react-native - React-native Flatlist 问题不使用 fetch api 呈现单个项目
- javascript - 如何以动态方式从一个元素到另一个元素绘制一条线?
- sql - 日期时间 SQL 语句(在 SQL Developer 中工作)
- c++ - 来自非零坐标的向量中的 8 邻域
- python - 如果我从实例调用 driver.close() ,它不会关闭 selenium 上的选项卡