×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

2-D "for/while" statement

2-D "for/while" statement

2-D "for/while" statement

(OP)
Hello, I've been stumped for several weeks on this particlar program.  At work here, we have 30 machines that we record scrap data on.  I take this data and create spreadsheets (boring) that can be used for analysis.  Anyway, I was wondering how I could change this "for" statement to a much more condensed amount of code.

for i in range(30):
    while hold[n,3] == 1:
        hold_01.append( hold[n,8] )
        hDate_01.append( hold[n,0] )
        n = n + 1
    while hold[n,3] == 2:
        hold_02.append( hold[n,8] )
        hDate_02.append( hold[n,0] )
        n = n + 1
    while hold[n,3] == 3:
... and so on, for a total of 30 machines.

Is there anyway to alter the line(s) with the .append from a 1-D vector to a 2-D array, so I can set me while loop == i, and add the data from hold[] to the next row, and so on.  Any help would be greatly appreciated.

Thanks,
~~archeryguru2000~~

RE: 2-D "for/while" statement

Hello,

I am a newcomer to the Python language, so I could be completely wrong.  I did find this example that looks like you can define a multi-dimensional array.  I don't know if this example requires the Numeric Module or not but worth a try anyway.

http://www.penzilla.net/tutorials/python/numeric/

For example (steps through a 30x10x100 array if the array already has data in it)

for i in range(30)
  for j in range(10)
    for k in range(100)
       element = aData[i][j][k]
       print element

Best of Luck.
Andy

RE: 2-D "for/while" statement

Dear Archeryguru2000,

it's not completely clear what you are trying to achieve. Because what is the type of the 'hold' element. What is the information it's holding? I don't really follow the use of the comma.

That said, if you want to replace the long loop, you can replace the 30 repeats of the same type of code with a fairly simple solution:

CODE

locals()

Using this function you can dynamicly call your local values, e.g: hold_01, hold_02 etc...

so if you would use your old code it now would look like this:

CODE

while hold[n,3] <= 31:
        locals()['hold_%.2d' % n].append(hold[n,8])
        locals()['hDate_%.2d' % n].append(hold[n,0])
        n = n + 1

I'm not entirely sure under what condition you want it to stop but I just guessed, that the value coming from hold[n,3] is the same as the machine you're trying to write it to.

Yet again, I'm not sure what the square brackets are for by the 'hold' element. Please shine your light on that.

Bye Matey

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close