1

I have a numpy matrix of size 3X3 and I am trying to insert a list into a matrix. But it gives the following error:

ValueError: setting an array element with a sequence.

The following code is here:

for ind1, var1 in enumerate(combined_edges[0]):
        for ind2, var2 in enumerate(combined_edges[1]):
            t,u, xm,ym,xn,yn,xo,yo,xr,yr, bool = edgeIntersect(var1,var2)
            if bool == False:
                print("There is no intersection")
                intersectMat[ind1][ind2] = 0
            else:
                t = int(t) if np.asscalar(t).is_integer() else t
                u = int(u) if np.asscalar(u).is_integer() else u
                alpha = var1[0].point()[0] + t*(var1[1].point()[0] - var1[0].point()[0])
                beta = var1[0].point()[1] + t*(var1[1].point()[1] - var1[0].point()[1])
                new_node = Node((alpha,beta), mark=True)
                print(new_node.point())
                intersectMat[ind1][ind2] = array(new_node.point(), dtype=int)

Any suggestion ??

  • Means exactly what it says, you're trying to cram a sequence of numbers into a single number slot. It can be thrown under various circumstances. https://stackoverflow.com/questions/4674473/valueerror-setting-an-array-element-with-a-sequence – DirtyBit Jan 24 '19 at 14:41
  • I did this but it again gives the error. – Kishan Kumar Jan 24 '19 at 14:45

1 Answers1

1

Numpy arrays are not like ordinary python lists (or lists of lists; or lists of lists of lists ...). They cannot store sequences at particular addresses.

QuantumChris
  • 963
  • 10
  • 21