ValueError: At least one stride in the given numpy array is negative

问题描述

torch.Tensor(array)时,报错:ValueError: At least one stride in the given numpy array is negative, and tensors with negative strides are not currently supported. (You can probably work around this by making a copy of your array with array.copy().)
ValueError: At least one stride in the given numpy array is negative_第1张图片


原因分析:

主要原因是Nunmpy中,随机初始化的数组默认都是C连续的,经过slice操作后,其连续性被改变,需要’numpy.ascontinguousarray(array)',使内存不连续的array转换为内存连续存储的数组。

你可能感兴趣的:(numpy,python,深度学习)