python - How to fill 2d numpy array with some 2d numpy array
问题描述
I have a 2d numpy array which varies in size from one value to other.
How can I generalize the size by filling in zeros if the input value has less dimension than required?
Exmaple:
Input list with numpy array dimension:
[(40, 173),
(40, 14),
(40, 56),
(40, 173)]
And I want to have all the arrays to be (40, 173), where if it is has lesser size, than filling rest with zeros.
解决方案
分配给zeros
数组:
In [160]: res = np.zeros((40,173),int)
In [161]: res[0:20, 0:30] = np.ones((20,30),int)
推荐阅读
- c# - 为什么我的按钮不使用我创建的样式?
- python - 通过按下具有不同输入值的按钮动态调用函数
- javascript - 如何同时在 vue js 上添加两个转换?
- javascript - 代码重构。试图改进我的代码
- python-3.x - Python 硒火狐使用 .click() 选择
- python - 用一个简单的语句制作两个条件/循环语句在一条 python 行中工作
- makefile - 试图理解为什么 make 失败
- mysql - 通过 vsts 调用表达式返回以代码“1”退出
- amazon-web-services - 将云端请求重定向到新 URL
- angular - PrimeNg 饼图 - 默认显示所有工具提示?