changing sequence to array

A

amitsoni.1984

Hi,
I am using the code given below where A is a matrix and row is a
sequence. But it gives following error:

-------- error------
A[a,:]=row
ValueError: setting an array element with a sequence.

--------------code----------------
#!/usr/bin/python
import numpy
file1 = open('matrix.txt', 'r')

count = 0
a=0
b=0
c=0
d=0
e=0
A = numpy.zeros([4,4])
B= numpy.zeros([4,4])
C = numpy.zeros([4,4])
D = numpy.zeros([4,4])
E = numpy.zeros([4,4])
while 1:
lineStr = file1.readline()
if not(lineStr):
break

count = count + 1
row=lineStr.split()
if count<=4:
A[a,:]=row
a=a+1
elif count<=8:
B[b,:]=row
b=b+1
elif count<=12:
C[c,:]=row
c=c+1
elif count<=16:
D[d,:]=row
d=d+1
elif count<=20:
E[e,:]=row
e=e+1

file1.close()
---------end of code-------------

is there any way to change a sequence to array so that the above
operation could be executed?
thank you
Amit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top