Issue
I have a tensor with values between -1 and 1 . How can I get a new tensor such that where were negative values now there will be one and where were positive numbers now there will be 1? (efficiently)
Namely,
tensor1 = [-0.1, 0.5, 0.08]
new_tensor = [-1, 1, 1]
and zero will be -1 or 1
Solution
With numpy it is trivial:
import numpy as np
tensor1 = [-0.1, 0.5, 0.08]
new_tensor = np.sign(tensor1)
new_tensor[new_tensor==0] = 1
Answered By - Giovanni Tardini
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.