在第三方提供的numpy数据集上运行时,遇到了以下异常:
ValueError: When changing to a larger dtype, its size must be a divisor of the total size in bytes of the last axis of the array
Run Code Online (Sandbox Code Playgroud)
在什么情况下numpy会引起这种情况?我的代码在numpy数组上应用视图,在这里我试图应用dtype与行中元素数量匹配的结构化视图。
我在X.view([('', X.dtype)] * X.shape[1])函数内部调用语句时看到此错误f-但不是在每次对该函数的调用中都这样f:
ipdb> X.view([('', X.dtype)] * X.shape[1])
*** ValueError: When changing to a larger dtype, its size must be a divisor of the total size in bytes of the last axis of the array.
Run Code Online (Sandbox Code Playgroud)
X总是有两个轴(数组len(X.shape)始终是2),所以你会期望一个结构dtype是X.shape[1]长期适应的最后一个轴( …