You need to take care of the zero element of the subspace. for x in i will iterate over all the vectors including the zero vector.