python - Creating matrices in Numpy? -
i've tried different ways can't understand why cannot create matrix in numpy.
i "typeerror: new() takes 2 4 positional arguments 5 given" error when call:
def creategst(dictionary): x = int(dictionary['x']) y = int(dictionary['y']) z = int(dictionary['z']) matrix = np.matrix( (str(1),str(0),str(0),str(x)),(str(0),str(1),str(0),str(y)),(str(0),str(0),str(1),str(z)),(str(0),str(0),str(0),str(1)) ) return matrix it did not work without typecasting str(). i'm using python 3.4.
the answer right in error message. you're passing 5 parameters np.matrix:
matrix = np.matrix((str(1), str(0), str(0), str(x)), (str(0), str(1), str(0), str(y)), (str(0), str(0), str(1), str(z)), (str(0), str(0), str(0), str(1))) np.matrix not take 5 parameters. meant do:
matrix = np.matrix(((str(1), str(0), str(0), str(x)), (str(0), str(1), str(0), str(y)), (str(0), str(0), str(1), str(z)), (str(0), str(0), str(0), str(1)))) notice parentheses.
Comments
Post a Comment