python - np.reshape 1d 数组到 2d 数组 - 选择正确的尺寸
问题描述
我正在尝试使用 numpy 的 reshape 将 1d 数组重塑为 2d 数组:
import numpy as np
inputArray =np.random.randint(low=0, high=4, size=160000)
inputArray_ = inputArray.reshape(-1,4000, 4000,4)
返回值错误:
ValueError: cannot reshape array of size 160000 into shape (400,400,4)
解决方案
利用
inputArray_ = np.reshape(inputArray, (-1, 2))
或者
inputArray_ = np.reshape(inputArray, (len(inputArray)/2,2))
推荐阅读
- dart - 如何在 ArrayCouples 的飞镖中创建一个函数
- excel - 使用 VBA 求和并拖动公式
- php - 根据属性名称将 Eloquent 集合拆分为多个数组
- python - 在 pandas 的三列中选择具有匹配值的行
- swift - Swift:从磁盘缓存 int
- apollo - 在第二个阿波罗客户端 useQuery 调用后数据未刷新
- reactjs - 使用对象数组显示 FlatList
- node.js - 如何从给定的 url 下载文件到带有库的缓冲区?
- javascript - Euler 20 阶乘数字和项目
- dynamics-crm - 使用 CrmServiceClient 的 CreateNewActivityEntry 创建 Activity