Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35846
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2012-12-31 02:02 -0800 |
| Message-ID | <db8edd31-78f2-4e8c-a6bd-37e1e83ff2ee@googlegroups.com> (permalink) |
| Subject | Question about nested loop |
| From | Isaac Won <winefrog@gmail.com> |
Hi all,
I am a very novice for Python. Currently, I am trying to read continuous columns repeatedly in the form of array.
my code is like below:
import numpy as np
b = []
c = 4
f = open("text.file", "r")
while c < 10:
c = c + 1
for columns in ( raw.strip().split() for raw in f ):
b.append(columns[c])
y = np.array(b, float)
print c, y
I thought that can get the arrays of the columns[5] to [10], but I only could get repetition of same arrays of columns[5].
The result was something like:
5 [1 2 3 4 ......, 10 9 8]
6 [1 2 3 4 ......, 10 9 8]
7 [1 2 3 4 ......, 10 9 8]
8 [1 2 3 4 ......, 10 9 8]
9 [1 2 3 4 ......, 10 9 8]
10 [1 2 3 4 ......, 10 9 8]
What I can't understand is that even though c increased incrementally upto 10, y arrays stay same.
Would someone help me to understand this problem more?
I really appreciate any help.
Thank you,
Isaac
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Question about nested loop Isaac Won <winefrog@gmail.com> - 2012-12-31 02:02 -0800
Re: Question about nested loop Gisle Vanem <gvanem@broadpark.no> - 2012-12-31 12:25 +0100
Re: Question about nested loop Isaac Won <winefrog@gmail.com> - 2012-12-31 14:02 -0800
Re: Question about nested loop Isaac Won <winefrog@gmail.com> - 2012-12-31 14:02 -0800
Re: Question about nested loop Hans Mulder <hansmu@xs4all.nl> - 2012-12-31 13:59 +0100
Re: Question about nested loop Isaac Won <winefrog@gmail.com> - 2012-12-31 14:11 -0800
csiph-web