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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.04; 'element': 0.07; '3.0,': 0.09; 'answering': 0.09; 'method,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'wrote': 0.14; '6.0,': 0.16; 'array.': 0.16; 'check.': 0.16; 'enough.': 0.16; 'loop.': 0.16; 'presume': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:array': 0.16; 'split': 0.19; 'not,': 0.20; 'subject:] ': 0.20; 'putting': 0.22; 'print': 0.22; "shouldn't": 0.24; 'question': 0.24; 'post': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'tried': 0.27; 'specified': 0.30; "i'm": 0.30; 'code': 0.31; 'lines': 0.31; 'jean': 0.31; 'steven': 0.31; 'yourself.': 0.31; 'file': 0.32; 'totally': 0.33; 'comment': 0.34; 'problem': 0.35; "can't": 0.35; 'convert': 0.35; 'but': 0.35; 'really': 0.36; 'thanks': 0.36; 'two': 0.37; 'list': 0.37; 'clear': 0.37; 'e.g.': 0.38; 'to:addr :python-list': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'how': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'tell': 0.60; 'numbers': 0.61; 'first': 0.61; "you'll": 0.62; 'skip:n 10': 0.64; 'different': 0.65; 'dear': 0.65; '4.0,': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re: [newbie] confusion concerning fetching an element in a 2d-array
Date Tue, 25 Mar 2014 10:42:13 -0400 (EDT)
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>
X-Gmane-NNTP-Posting-Host dpc6744198232.direcpc.com
X-Newsreader PiaoHong Usenet NewsReaders 1.36
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.8524.1395758247.18130.python-list@python.org> (permalink)
Lines 51
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1395758247 news.xs4all.nl 2880 [2001:888:2000:d::a6]:37025
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:69035

Show key headers only | 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