Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #69035

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

From Dave Angel <davea@davea.name>
Subject Re: [newbie] confusion concerning fetching an element in a 2d-array
Date 2014-03-25 10:42 -0400
Organization news.gmane.org
References <82a05fdc-1f5c-4c9b-9718-09930977268c@googlegroups.com> <53316211$0$29994$c3e8da3$5496439d@news.astraweb.com> <dba12f0e-f169-430a-9785-b98841fd55d0@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.8524.1395758247.18130.python-list@python.org> (permalink)

Show all headers | View raw


 Jean Dubois <jeandubois314@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.

First write some code to split and convert each line into floats.
 You don't even try that in your original.  Then do that in a
 loop. Now you have all the floats in one list or array. I presume
 that it's two dimensional.  Use print to check.  If it's not, 
 you'll have to either post process it with a reshape method,  or
 change the way you accumulate it. I can't help with the latter.
 



-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[newbie] confusion concerning fetching an element in a 2d-array Jean Dubois <jeandubois314@gmail.com> - 2014-03-25 03:26 -0700
  Re: [newbie] confusion concerning fetching an element in a 2d-array Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-25 11:01 +0000
    Re: [newbie] confusion concerning fetching an element in a 2d-array Jean Dubois <jeandubois314@gmail.com> - 2014-03-25 06:47 -0700
      Re: [newbie] confusion concerning fetching an element in a 2d-array Dave Angel <davea@davea.name> - 2014-03-25 10:42 -0400
        Re: [newbie] confusion concerning fetching an element in a 2d-array Mark H Harris <harrismh777@gmail.com> - 2014-03-25 11:40 -0500
        Re: [newbie] confusion concerning fetching an element in a 2d-array Mark H Harris <harrismh777@gmail.com> - 2014-03-25 11:40 -0500
        Re: [newbie] confusion concerning fetching an element in a 2d-array Jean Dubois <jeandubois314@gmail.com> - 2014-03-25 11:58 -0700
          Re: [newbie] confusion concerning fetching an element in a 2d-array Joel Goldstick <joel.goldstick@gmail.com> - 2014-03-25 15:15 -0400
            Re: [newbie] confusion concerning fetching an element in a 2d-array Jean Dubois <jeandubois314@gmail.com> - 2014-03-26 01:48 -0700
          Re: [newbie] confusion concerning fetching an element in a 2d-array Dave Angel <davea@davea.name> - 2014-03-25 15:58 -0400
            Re: [newbie] confusion concerning fetching an element in a 2d-array Jean Dubois <jeandubois314@gmail.com> - 2014-03-26 01:47 -0700
      Re: [newbie] confusion concerning fetching an element in a 2d-array Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-25 15:35 +0000
      Re: [newbie] confusion concerning fetching an element in a 2d-array Peter Otten <__peter__@web.de> - 2014-03-25 17:12 +0100
        Re: [newbie] confusion concerning fetching an element in a 2d-array Jean Dubois <jeandubois314@gmail.com> - 2014-03-25 11:33 -0700

csiph-web