Python:为什么将 Dask 切片复制到 Numpy 数组会导致行数不匹配

标签 python arrays numpy dask

将 dask 数组的切片复制到 nparray 时出现错误,行数不匹配

store = h5py.File(s_file_path + '.hdf5', 'r')
dset = store['data_matrix']
data_matrix = da.from_array(dset, chunks=dset.chunks)
test_set = data_matrix[482:, :]
np_test_set = np.array(test_set, order='FORTRAN')

print "source_set shape: ", data_matrix.shape
print "test_set shape: ", test_set.shape
print "np_test_set shape: ", np_test_set.shape

结果:

source_set shape:  (656, 473034)
test set shape:  (174, 473034)
np_test_set shape:  (195, 473034)

我对 dask 不太熟悉,我使用它是因为我的数据不保存在 RAM 中,行差异与缓存或 block 大小有关吗?

最佳答案

转换为 numpy 数组的典型方法

您可以通过调用.compute方法将dask.array转换为numpy数组

np_test_set = test_set.compute()

或通过调用np.asarray

np_test_set = np.asarray(test_set)

Fortran 排序

原则上你现在所做的应该也可以正常工作,所以这可能是一个错误。其中唯一看起来不典型的部分是提前指定 Fortran 顺序。看看改变这个是否会影响结果会很有趣。

其他信息

如果这是一个真正的错误(看起来可能是)那么最好 raise an issue 。看到 dask.array 的 block 也会很有用。

关于Python:为什么将 Dask 切片复制到 Numpy 数组会导致行数不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34456338/

相关文章:

python - 为什么 NumPy int 不是 Python int 的实例,而 NumPy float 是 Python float 的实例?

python - 使用 ndimage.interpolation.affine_transform 进行矩阵平移

python - 在 GqlQuery 的 where 子句中使用本地时间

python - 如何将 3D 模型的 .obj 格式转换为 .json 格式?

php - 是否可以在所需循环之外创建数据库调用?

javascript - 在javascript中如何在具有嵌套数组的对象数组中查找值

arrays - 使用 SciPy 读取 MATLAB MAT 文件时出现 "Expecting miMATRIX type"错误

python - 在 Python 中使用 Apps Script Execution API 时出现 404 错误

python - 如何在 Windows XP/7 机器上找到内存中的字节序列?

javascript - 如何在 JavaScript 中实例化多维数组?