当前位置: 代码迷 >> 综合 >> theano TypeError: Cannot convert Type TensorType(int32, matrix) (of Variable Subtensor{int64:int64:}
  详细解决方案

theano TypeError: Cannot convert Type TensorType(int32, matrix) (of Variable Subtensor{int64:int64:}

热度:85   发布时间:2023-12-15 17:04:25.0

报错:TypeError: Cannot convert Type TensorType(int32, matrix) (of Variable Subtensor{int64:int64:}.0) into Type TensorType(int32, vector). You can try to manually convert Subtensor{int64:int64:}.0 into a TensorType(int32, vector).

原因:numpy数组的shape没有转成(-1, )就直接丢给theano用了,1维的numpy数组会被theano认为是matrix,而不是vector。所以需要你先手动转换一下。

解决:

方法一:test_raw_y.flatten() 

方法二:test_raw_y.reshape((-1)) 

 

 

感谢:https://theano-users.narkive.com/59N7go8o/re-typeerror-cannot-convert-type-tensortype-int32-matrix-of-variable-subtensor-int64-int64-0-into

  相关解决方案