Reputation: 335
I have a variable which is an uint8 type (it has just two values, 0 and 1), and I want to replace the zeros with -1. Do I have first to transform this variable to int64 (or any integer data type that allows negative numbers)? If so, how could I achieve it?
Upvotes: 5
Views: 23097
Reputation: 1344
You don't need int64. int8 should make it. to convert uint8 into int8 :
import numpy as np
x = np.uint8(-1) # -1 does not exist in this coding, this is just a test
x
> 255
np.int8(x)
> -1 # eureka
Upvotes: 3