Hi,
I found that ndarray is the wrong class to use for this purpose. The
vector I created in the example below was just en uninitialised 3D
vector. Arrays cannot be subclassed:
class Vector(np.array):
pass
returns an error. But using a matrix as base class works:
class Vector(np.matrix):
Hi,
I am trying to create an ndarry subclass for vector calculations. The
result is not what I intent:
import numpy as np
class Vector(np.ndarray):
def __abs__(self):
return(np.sqrt(sum(self**2)))
V = Vector([1,2,3])
print np.sqrt(sum(self**2))
print abs(V)
I do not und