theano reshape -1

import theano
import numpy as np

ones = theano.shared(np.float32([[1,2,3],[4,5,6],[7,8,9]]))

print(ones.get_value())

print(ones.reshape([1,-1]).eval())

print(ones.reshape((1,-1)).eval())

print(ones.reshape((-1,)).eval())

print(ones.reshape((-1,1)).eval())

# print(ones.reshape((2,-1)).eval()) # ValueError: Cannot reshape input of shape (3, 3) to shape [ 2 -1]

结果

[[ 1. 2. 3.]
[ 4. 5. 6.]
[ 7. 8. 9.]]

[[ 1. 2. 3. 4. 5. 6. 7. 8. 9.]]

[[ 1. 2. 3. 4. 5. 6. 7. 8. 9.]]

[ 1. 2. 3. 4. 5. 6. 7. 8. 9.]

[[ 1.]
[ 2.]
[ 3.]
[ 4.]
[ 5.]
[ 6.]
[ 7.]
[ 8.]
[ 9.]]

你可能感兴趣的:(Python,theano)