equal¶
- nvtripy.equal(input: Tensor, other: Tensor) bool [source]¶
Returns
True
ifinput
andother
have the same shape and elements.- Parameters:
- Returns:
True
if the tensors have the same shape and elements andFalse
otherwise.- Return type:
Example: Identical tensors
1a = tp.ones((1, 2), dtype=tp.float32) 2b = tp.ones((1, 2), dtype=tp.float32) 3 4is_equal = tp.equal(a, b)
>>> a tensor( [[1.0000, 1.0000]], dtype=float32, loc=gpu:0, shape=(1, 2)) >>> b tensor( [[1.0000, 1.0000]], dtype=float32, loc=gpu:0, shape=(1, 2)) >>> is_equal True
Example: Different shapes
1a = tp.ones((1, 2), dtype=tp.float32) 2b = tp.ones((2, 2), dtype=tp.float32) 3 4is_equal = tp.equal(a, b)
>>> a tensor( [[1.0000, 1.0000]], dtype=float32, loc=gpu:0, shape=(1, 2)) >>> b tensor( [[1.0000, 1.0000], [1.0000, 1.0000]], dtype=float32, loc=gpu:0, shape=(2, 2)) >>> is_equal False
Example: Different elements
1a = tp.ones((1, 2), dtype=tp.float32) 2b = tp.zeros((1, 2), dtype=tp.float32) 3 4is_equal = tp.equal(a, b)
>>> a tensor( [[1.0000, 1.0000]], dtype=float32, loc=gpu:0, shape=(1, 2)) >>> b tensor( [[0.0000, 0.0000]], dtype=float32, loc=gpu:0, shape=(1, 2)) >>> is_equal False