[newbie] confusion concerning fetching an element in a 2d-array

Jean Dubois jeandubois314 at gmail.com
Tue Mar 25 14:58:11 EDT 2014


Op dinsdag 25 maart 2014 15:42:13 UTC+1 schreef Dave Angel:
> Jean Dubois <jeandubois314 at gmail.com> Wrote in message:
> > Op dinsdag 25 maart 2014 12:01:37 UTC+1 schreef Steven D'Aprano:
> >>
> >> py> values = [float(s) for s in data.split()]
> >> py> print values
> >> [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
> >> py> array_lines = np.array(values)
> >> py> array_lines = array_lines.reshape(3, 3)
> >> py> print array_lines
> >> [[ 1.  2.  3.]
> >>  [ 4.  5.  6.]
> >>  [ 7.  8.  9.]]
> >>
> > Dear Steve,
> > Thanks for answering my question but unfortunately now I'm totally
> > confused. 
> > Above I see parts from different programs which I can't
> > assemble together to one working program (I really tried hard).
> > Can I tell from your comment I shouldn't use numpy?
> > I also don't see how to get the value an element specified by (row,
> > column) from a numpy_array like "array_lines" in my original code
> I don't use numpy,  but I thought Steven's description was clear
>  enough.
> Your problem was not the extraction,  but the creation of the
>  array.  Use print to prove that to yourself. 
> > 
> > All I need is a little python-example reading a file with e.g. three lines
> > with three numbers per line and putting those numbers  as floats in a
> > 3x3-numpy_array, then selecting an element from that numpy_array using
> > it's row and column-number.
> If your instructor wanted you to copy examples,  he would have
>  given you one.
please Dave leave that belittling tone behind, there's no instructor
whatsoever involved here. I constructed this example myself as I know very
well I have to start with little pieces of code first to be able to master
larger problems later. I just wanted to figure this example out first,
and as I now learned from Peter's marvellous explanation there _is_ an
elegant solution in Python to this kind of problem.
So if you are irritated by newbie-questions in the future, just neglect
them

thanks
jean



More information about the Python-list mailing list