I didn’t quite understand the difference between np.sign, and np.asscalar, having tried the side_of_plane function as shown on lecture, with the dot-product of P with the example vectors v1,v2,v3, With both np.sign and np.asscalar I got 1, 0, -1 respectively.
The results were the same, whether I used np.sign or np.asscalar with the same vectors. What’s the difference then and why doesn’t it show on the result I got?
Hi @Doron_Modan
The functions np.sign
and np.asscalar
are quiet different:
-
np.sign
: Returns the sign of each element in the input array (-1 for negative, 0 for zero, 1 for positive) → affects the value by giving its sign -
np.asscalar
: Converts an array of size 1 to a scalar → does not change the value, only its type
The results were the same because you compared scalar values, where np.sign
provided the signs directly, and np.asscalar
just converted the single-value result without affecting the sign computation.
Hope it helps! Feel free to ask if you need further assistance.
Thank you for your reply. Could you please give me an example of vectors and Plane, where the results of the 2 functions are different?