np.astype uint8之后发生了什么
uint8变成float没什么好说的就是添加了.0那float变成uint8到底发生了什么呢b = np.arange(10).astype('float32')c = -bb[9] = 0.7print('b',b)print('c',c)print(b.astype('uint8'))print(c.astype('uint8'))输出b [0.1.2.3.4.5.6.7.8.0.7]c [-
·
uint8变成float没什么好说的就是添加了.0
那float变成uint8到底发生了什么呢
b = np.arange(10).astype('float32')
c = -b
b[9] = 0.7
print('b',b)
print('c',c)
print(b.astype('uint8'))
print(c.astype('uint8'))
输出
b [0. 1. 2. 3. 4. 5. 6. 7. 8. 0.7]
c [-0. -1. -2. -3. -4. -5. -6. -7. -8. -9.]
[0 1 2 3 4 5 6 7 8 0]
[ 0 255 254 253 252 251 250 249 248 247]
`**加粗样式**``
总结 小数部分直接截去,0-255之间的整数保留
然后循环 没有求什么最大最小值然后变成0-255的做法! 就是截取跟比对

更多推荐



所有评论(0)