1.两种方式:array.dtype=np.uint8 或是 array=array.astype( np.uint8 )
2.使用array=array.astype( np.uint8 )的时候必须astype后赋值,只是用array.astype( np.uint8 ) 是不会改变数据类型的,必须写成array=array.astype( np.uint8 )。
本文介绍了将数据类型转换为np.uint8的两种方法。一种是直接使用array.dtype=np.uint8,另一种是利用astype方法并确保结果被赋值给原变量,即array=array.astype(np.uint8)。值得注意的是,仅使用astype方法不会改变原始数组的数据类型。
1.两种方式:array.dtype=np.uint8 或是 array=array.astype( np.uint8 )
2.使用array=array.astype( np.uint8 )的时候必须astype后赋值,只是用array.astype( np.uint8 ) 是不会改变数据类型的,必须写成array=array.astype( np.uint8 )。
768
3287