How do I interpret
TypeError: unsupported format string passed to numpy.ndarray.format
when I am trying to compute the sum of the squared differences of the components of two vectors?
How do I interpret
TypeError: unsupported format string passed to numpy.ndarray.format
when I am trying to compute the sum of the squared differences of the components of two vectors?
Hi
if you want to print any format you must use list like that
import numpy as np
x = np.array([1.2334, 2.3455, 3.456], dtype=np.float32)
print( list(map(‘{:.2f}%’.format,x)))
but if you want to compute sum of the squared differences of the components of two vectors(X,Y)
you can use np.sum((X-Y)**2,axis = ?) ? = 0 if you want to do sum over rows and 1 is if you want to do sum over columns
please feel free to ask any questions,
Thanks,
Abdelrahman
Thanks! That seemed to do the trick. There are so many ways to do things in NumPy. I was trying to use np.square and np.subtract - would I have had to do something special (np.array?) with the vectors a and b?
Hi @Richard_Rasiej
yes you can use
np.sum(np.square(np.subtract(x,y)),axis=?) ? = 0 if you want to do sum over rows and 1 is if you want to do sum over columns
hi @AbdElRhaman_Fakhry please help with this,
NameError: name ‘test_sq_dist’ is not defined .
Do I use a loop
Hi @Junta442
you want to restart the kernel and after that you must make sure you run all the cell specially the the import libraries cell
please feel free to ask any questions,
Thanks,
Abdelrahman
@AbdElRhaman_Fakhry Thanks that seemed to do it