# test if v.norm <> zero pb [closed]

HI I do not understand why if v.norm !=0 does not work here.

ZeroDivisionError: rational division by zero

def normalizeVectorL(vectorList) :
vNormList=[]
for l in vectorList :
lMatrixList=[]
for v in l :
v=vector(v)
z=zero_vector(v.length())
#if v != z  :
if v.norm() != 0 :

show("v :\t",v,"v.norm() :\t",v.norm())
lMatrixList.append(matrix(v/v.norm()).transpose())
else :
lMatrixList.append(matrix(v).transpose())

vNormList.append(lMatrixList)
return vNormList

VVVlist=[]
VVVlist0=[]
VVVlist0.append([1,1,1])
VVVlist0.append([1,1,2])
VVVlist0.append([1,0,0])
VVVlist.append(VVVlist0)

VVVlist1=[]
VVVlist1.append([1,3,1])
VVVlist1.append([1,2,2])
VVVlist1.append([0,0,0])
VVVlist.append(VVVlist1)

show(VVVlist)
show(normalizeVectorList(VVVlist))

edit retag reopen merge delete

### Closed for the following reason not a real question by ortollj close date 2019-11-25 13:14:44.643826

Sort by ยป oldest newest most voted

It works for me, except I had to change normalizeVectorList to normalizeVectorL which is the name of the function you defined in your example. Please make sure you are running the actual code you think you're running by creating and verifying a Minimal, Complete, Reproducible Example.

As an aside I'm a little confused by this construction and the one below it:

VVVlist=[]
VVVlist0=[]
VVVlist0.append([1,1,1])
VVVlist0.append([1,1,2])
VVVlist0.append([1,0,0])
VVVlist.append(VVVlist0)


This is just equivalent to writing:

VVVlist = [[[1, 1, 1], [1, 1, 2], [1, 0, 0]]]


and so on. You can nest list literals as much as you need to and I think it makes for much clearer code.

more

1

OOps, sorry I changed the name, and I did not see the old one was still present !

( 2019-11-25 13:09:59 +0200 )edit