I have this code. Everything works fine.
P = np.matrix(' \
1 0.5 0.5 0.5 \
')
print( P )
The output is [[1. 0.5 0.5 0.5]]
I want to make the same matrix without using a string. So I tried
P = [[ 1, 0.5, 0.5, 0.5 ]]
print( P )
The output is slightly different. It is
[[1, 0.5, 0.5, 0.5]]
The second version does not suit my purpose. The following code works with the first version but not the second.
p = (P - 1/2)* 2 * scale()
TypeError: unsupported operand type(s) for -: 'list' and 'float'
So...how do I get the first version of the matrix without making it from a string?
不使用字符串的相同矩阵:
P = np.matrix([[1., 0.5, 0.5, 0.5]])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.