changing sequence to array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • amitsoni.1984@gmail.com

    #1

    changing sequence to array

    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.tx t', '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.spl it()
    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

Working...