audio /= np.max(np.abs(audio),axis=0)image *= (255.0/image.max())
使用
/=和
*=可以消除中间的临时阵列,从而节省了一些内存。乘法比除法便宜,所以
image *= 255.0/image.max() # Uses 1 division and image.size multiplications
比…快一点
image /= image.max()/255.0 # Uses 1+image.size divisions
由于我们在这里使用基本的numpy方法,因此我认为这是尽可能有效的numpy解决方案。
就地操作不会更改容器数组的dtype。由于所需的标准化值是浮点型,因此在执行就地操作之前,
audioand
image数组需要具有浮点数dtype。如果它们还不是浮点dtype,则需要使用进行转换
astype。例如,
image = image.astype('float64')


