1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Python array error

  1. Jan 9, 2012 #1
    1. The problem statement, all variables and given/known data

    fname='%05s - %05s . %05s - %05s' % (xstart,xend,ystart,yend)
    gives the error
    ValueError: setting an array element with a sequence.

    Basically I wanted to turn the statement '%05s - %05s . %05s - %05s' % ('50','50','50','50') to a string/name
    that goes into an array of names

    how?
    Cheers

    2. Relevant equations



    3. The attempt at a solution
     
  2. jcsd
  3. Jan 9, 2012 #2
    This works fine for me in python 3.x. Of course, I did have to initialize the array with prior data. I used i=2. Perhaps you could post a compete chunk of code that fails?
     
  4. Jan 9, 2012 #3
    def makeFName(row,col,res):

    mod = row%res
    if(mod !=0):
    j=((row-mod)/res)+1
    else:
    j=row/res
    mod=col%res1
    if(mod !=0):
    k=((col-mod)/res)+1
    else:
    k=col/res

    fname=numpy.zeros((1,j*k))
    print fname
    xstart=1
    ystart=1
    i=0


    while(xstart < row):
    while(ystart < col):
    fname='%05d - %05d . %05d - %05d' % (xstart,
    10,
    10,
    10)
    ystart+=res
    i+=1
    xstart+=res
    print fname
     
  5. Jan 9, 2012 #4
    sorry about indentation, doesn't work when i copy / paste it for some reason
     
  6. Jan 9, 2012 #5

    Dick

    User Avatar
    Science Advisor
    Homework Helper

    Your main problem is that you are trying to put strings into a numpy numeric array. You can't do that. I don't know why you would want to initialize an array with numpy to begin with if you want to store strings. There are a number of other things I don't understand either. But that's the first thing that catches my attention.
     
    Last edited: Jan 9, 2012
  7. Jan 10, 2012 #6

    Borek

    User Avatar

    Staff: Mentor

    Surround your code by [noparse]
    Code (Text):
     
    [/noparse] tags.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Python array error
  1. Python question (Replies: 2)

  2. Python syntax (Replies: 5)

  3. Python Beginner (Replies: 3)

  4. Python question (Replies: 1)

Loading...