Python arrays and sting formatting options

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ivan Reborin

    Python arrays and sting formatting options

    Hello everyone,

    I was wondering if anyone here has a moment of time to help me with 2
    things that have been bugging me.

    1. Multi dimensional arrays - how do you load them in python
    For example, if I had:
    -------
    1 2 3
    4 5 6
    7 8 9

    10 11 12
    13 14 15
    16 17 18
    -------
    with "i" being the row number, "j" the column number, and "k" the ..
    uhmm, well, the "group" number, how would you load this ?

    If fortran90 you would just do:

    do 10 k=1,2
    do 20 i=1,3

    read(*,*)(a(i,j ,k),j=1,3)

    20 continue
    10 continue

    How would the python equivalent go ?

    2. I've read the help on the next one but I just find it difficult
    understanding it.
    I have;
    a=2.000001
    b=123456.789
    c=1234.0001

    How do you print them with the same number of decimals ?
    (eg. 2.000, 123456.789, 1234.000)
    and how do you print them with the same number of significant
    decimals?
    (eg. 2.000001, 123456.7, 1234.000 - always 8 decimals) ?


    Is something like this possible (built-in) in python ?

    Really grateful for all the help and time you can spare.

    --
    Ivan
  • Mensanator

    #2
    Re: Python arrays and sting formatting options

    On Sep 29, 5:04 pm, Ivan Reborin <irebo...@delet e.this.gmail.co m>
    wrote:
    Hello everyone,
    >
    I was wondering if anyone here has a moment of time to help me with 2
    things that have been bugging me.
    >
    1. Multi dimensional arrays - how do you load them in python
    For example, if I had:
    -------
    1 2 3
    4 5 6
    7 8 9
    >
    10 11 12
    13 14 15
    16 17 18
    -------
    with "i" being the row number, "j" the column number, and "k" the ..
    uhmm, well, the "group" number, how would you load this ?
    >
    If fortran90 you would just do:
    >
    do 10 k=1,2
    do 20 i=1,3
    >
    read(*,*)(a(i,j ,k),j=1,3)
    >
    20 continue
    10 continue
    >
    How would the python equivalent go ?
    >
    2. I've read the help on the next one but I just find it difficult
    understanding it.
    I have;
    a=2.000001
    b=123456.789
    c=1234.0001
    >
    How do you print them with the same number of decimals ?
    (eg. 2.000, 123456.789, 1234.000)
    >>print '%0.3f' % 2.000001
    2.000
    >>print '%0.3f' % 123456.789
    123456.789
    >>print '%0.3f' % 1234.0001
    1234.000

    and how do you print them with the same number of significant
    decimals?
    (eg. 2.000001, 123456.7, 1234.000 - always 8 decimals) ?
    Your examples are 7 decimals (and you're not rounding).

    Here's what 8 looks like (note that it's %0.7e because there
    is always one digit to the left of the decimal point.)
    >>print '%0.7e' % 2.000001
    2.0000010e+00
    >>print '%0.7e' % 123456.789
    1.2345679e+05
    >>print '%0.7e' % 1234.0001
    1.2340001e+03

    If you actually meant 7, then use %0.6e:
    >>print '%0.6e' % 2.000001
    2.000001e+00
    >>print '%0.6e' % 123456.789
    1.234568e+05
    >>print '%0.6e' % 1234.0001
    1.234000e+03

    >
    Is something like this possible (built-in) in python ?
    You can do more with gmpy.
    >
    Really grateful for all the help and time you can spare.
    >
    --
    Ivan

    Comment

    • Ivan Reborin

      #3
      Re: Python arrays and sting formatting options

      On Mon, 29 Sep 2008 16:08:28 -0700 (PDT), Mensanator
      <mensanator@aol .comwrote:
      >2. I've read the help on the next one but I just find it difficult
      >understandin g it.
      >I have;
      >a=2.000001
      >b=123456.789
      >c=1234.0001
      >>
      Hello Mensanator, thank you for answering in such a short time.

      < snip >
      >If you actually meant 7, then use %0.6e:
      Sorry about that; I have the habit of counting the point as a decimal
      place too.
      >
      >>>print '%0.6e' % 2.000001
      >2.000001e+00
      >>>print '%0.6e' % 123456.789
      >1.234568e+05
      >>>print '%0.6e' % 1234.0001
      >1.234000e+03
      >
      I understood the above from help, but it's not what's been bugging me.
      Mea culpa, I've defined the question in a confusing way, I see that
      now. What I've meant to ask was, when I have 3 numbers, how would you
      print them with the same format which would apply to them 3 numbers.

      for example, I have
      print a,b,c

      now if I print them with
      print '%12.3f' %a,b,c
      the format will apply only to a, and not to b and c. I could of course
      write
      print '%12.3f %12.3f ... 3 times
      but that is just unpractical.

      Is there a way to just do something like this (not normal syntax, just
      my wishful thinking):
      print 3*'%12.3f' %a,b,c
      (meaning - use this format for the next 3 real numbers that come
      along)

      --
      Ivan

      Comment

      • bearophileHUGS@lycos.com

        #4
        Re: Python arrays and sting formatting options

        Ivan Reborin:
        Is there a way to just do something like this (not normal syntax, just
        my wishful thinking):
        print 3*'%12.3f' %a,b,c
        (meaning - use this format for the next 3 real numbers that come
        along)
        The Python genie grants you that wish. You were almost right:
        >>a = 2.000001
        >>b = 123456.789
        >>c = 1234.0001
        >>print (3 * '%12.3f') % (a, b, c)
        2.000 123456.789 1234.000
        >>print 3 * '%12.3f' % (a, b, c)
        2.000 123456.789 1234.000
        >>print 3 * '%12.3f' % a, b, c
        Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        TypeError: not enough arguments for format string

        (Note the spaces and parentheses. Python programmers thank you if put
        them improving readability a little).

        Bye,
        bearophile

        Comment

        • Ivan Reborin

          #5
          Re: Python arrays and sting formatting options

          On Mon, 29 Sep 2008 17:59:40 -0700 (PDT), bearophileHUGS@ lycos.com
          wrote:

          Hello bearophile, thank you for replying.
          >The Python genie grants you that wish. You were almost right:
          >>>print (3 * '%12.3f') % (a, b, c)
          2.000 123456.789 1234.000
          >>>print 3 * '%12.3f' % (a, b, c)
          2.000 123456.789 1234.000
          Works beautifully :-) Thank you!
          >>>print 3 * '%12.3f' % a, b, c
          >Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
          >TypeError: not enough arguments for format string
          Just one more question - it's actually an extension to this one
          (forgive my curiosity, but I really need this info, and searching
          google always gives me the same stuff again and again) ...

          a = 2.000001
          b = 123456.789
          c = 1234.0001
          d = 98765.4321
          # same as above except for d

          print (3 * '%12.3f') % (a, b, c)
          #this works beautifully

          How to add d at the end but with a different format now, since I've
          "used" the "format part" ?

          Again, my weird wishful-thinking code:
          print (3*'%12.3f', '%5.3f') %(a,b,c),d

          >(Note the spaces and parentheses. Python programmers thank you if put
          >them improving readability a little).
          Yes, ok. I can agree with that - separating the format from the
          variable list part sounds reasonable.
          >
          >Bye,
          >bearophile
          --
          Ivan

          Comment

          • Chris Rebert

            #6
            Re: Python arrays and sting formatting options

            On Mon, Sep 29, 2008 at 6:56 PM, Ivan Reborin
            <ireborin@delet e.this.gmail.co mwrote:
            On Mon, 29 Sep 2008 17:59:40 -0700 (PDT), bearophileHUGS@ lycos.com
            wrote:
            >
            Hello bearophile, thank you for replying.
            >
            >>The Python genie grants you that wish. You were almost right:
            >>>>print (3 * '%12.3f') % (a, b, c)
            > 2.000 123456.789 1234.000
            >>>>print 3 * '%12.3f' % (a, b, c)
            > 2.000 123456.789 1234.000
            Works beautifully :-) Thank you!
            >
            >>>>print 3 * '%12.3f' % a, b, c
            >>Traceback (most recent call last):
            > File "<stdin>", line 1, in <module>
            >>TypeError: not enough arguments for format string
            >
            Just one more question - it's actually an extension to this one
            (forgive my curiosity, but I really need this info, and searching
            google always gives me the same stuff again and again) ...
            >
            a = 2.000001
            b = 123456.789
            c = 1234.0001
            d = 98765.4321
            # same as above except for d
            >
            print (3 * '%12.3f') % (a, b, c)
            #this works beautifully
            >
            How to add d at the end but with a different format now, since I've
            "used" the "format part" ?
            >
            Again, my weird wishful-thinking code:
            print (3*'%12.3f', '%5.3f') %(a,b,c),d
            Again, very close to the correct code:

            print (3*'%12.3f' + '%5.3f') %(a,b,c,d)

            Regards,
            Chris
            >
            >
            >>(Note the spaces and parentheses. Python programmers thank you if put
            >>them improving readability a little).
            >
            Yes, ok. I can agree with that - separating the format from the
            variable list part sounds reasonable.
            >
            >>
            >>Bye,
            >>bearophile
            >
            --
            Ivan
            --

            >
            --
            Follow the path of the Iguana...

            Comment

            • Marc 'BlackJack' Rintsch

              #7
              Re: Python arrays and sting formatting options

              On Tue, 30 Sep 2008 03:56:03 +0200, Ivan Reborin wrote:
              a = 2.000001
              b = 123456.789
              c = 1234.0001
              d = 98765.4321
              # same as above except for d
              >
              print (3 * '%12.3f') % (a, b, c)
              #this works beautifully
              >
              How to add d at the end but with a different format now, since I've
              "used" the "format part" ?
              >
              Again, my weird wishful-thinking code: print (3*'%12.3f', '%5.3f')
              %(a,b,c),d
              Maybe you should stop that wishful thinking and programming by accident
              and start actually thinking about what the code does, then it's easy to
              construct something working yourself.

              The ``%`` operator on strings expects a string on the left with format
              strings in it and a tuple with objects to replace the format strings
              with. So you want

              '%12.3f%12.3f%1 2.3f%5.3f' % (a, b, c, d)

              But without repeating the '%12.3f' literally. So you must construct that
              string dynamically by repeating the '%12.3f' and adding the '%5.3f':

              In [27]: 3 * '%12.3f'
              Out[27]: '%12.3f%12.3f%1 2.3f'

              In [28]: 3 * '%12.3f' + '%5.3f'
              Out[28]: '%12.3f%12.3f%1 2.3f%5.3f'

              Now you can use the ``%`` operator on that string:

              In [29]: (3 * '%12.3f' + '%5.3f') % (a, b, c, d)
              Out[29]: ' 2.000 123456.789 1234.00098765.4 32'

              (I guess there should be at least a space before the last format string.)

              This time you *have* to put parenthesis around the construction of the
              format string BTW because ``%`` has a higher priority than ``+``. So
              implicit parentheses look like this:

              3 * '%12.3f' + '%5.3f' % (a, b, c, d)
              <=3 * '%12.3f' + ('%5.3f' % (a, b, c, d))

              And there are of course not enough formatting place holders for four
              objects in '%5.3f'.

              It's also important to learn why your wrong codes fail. In your wishful
              thinking example you will get a `TypeError` saying "unsupporte d operand
              type(s) for %: 'tuple' and 'tuple'". That's because on the left side of
              the ``%`` operator you wrote a tuple:

              In [34]: (3 * '%12.3f', '%5.3f')
              Out[34]: ('%12.3f%12.3f% 12.3f', '%5.3f')

              Ciao,
              Marc 'BlackJack' Rintsch

              Comment

              • Marc 'BlackJack' Rintsch

                #8
                Re: Python arrays and sting formatting options

                On Tue, 30 Sep 2008 00:04:18 +0200, Ivan Reborin wrote:
                1. Multi dimensional arrays - how do you load them in python For
                example, if I had:
                -------
                1 2 3
                4 5 6
                7 8 9
                >
                10 11 12
                13 14 15
                16 17 18
                -------
                with "i" being the row number, "j" the column number, and "k" the ..
                uhmm, well, the "group" number, how would you load this ?
                >
                If fortran90 you would just do:
                >
                do 10 k=1,2
                do 20 i=1,3
                >
                read(*,*)(a(i,j ,k),j=1,3)
                >
                20 continue
                10 continue
                >
                How would the python equivalent go ?
                Well, I don't know if this qualifies as equivalent:

                =====
                from __future__ import with_statement
                from functools import partial
                from itertools import islice
                from pprint import pprint


                def read_group(line s, count):
                return [map(int, s.split()) for s in islice(lines, count)]


                def main():
                result = list()

                with open('test.txt' ) as lines:
                #
                # Filter empty lines.
                #
                lines = (line for line in lines if line.strip())
                #
                # Read groups until end of file.
                #
                result = list(iter(parti al(read_group, lines, 3), list()))

                pprint(result, width=30)


                if __name__ == '__main__':
                main()
                =====

                The output is:

                [[[1, 2, 3],
                [4, 5, 6],
                [7, 8, 9]],
                [[10, 11, 12],
                [13, 14, 15],
                [16, 17, 18]]]

                `k` is the first index here, not the last and the code doesn't use fixed
                values for the ranges of `i`, `j`, and `k`, in fact it doesn't use index
                variables at all but simply reads what's in the file. Only the group
                length is hard coded in the source code.

                Ciao,
                Marc 'BlackJack' Rintsch

                Comment

                • Aidan

                  #9
                  Re: Python arrays and sting formatting options

                  Ivan Reborin wrote:
                  Hello everyone,
                  >
                  I was wondering if anyone here has a moment of time to help me with 2
                  things that have been bugging me.
                  >
                  1. Multi dimensional arrays - how do you load them in python
                  For example, if I had:
                  -------
                  1 2 3
                  4 5 6
                  7 8 9
                  >
                  10 11 12
                  13 14 15
                  16 17 18
                  -------
                  with "i" being the row number, "j" the column number, and "k" the ..
                  uhmm, well, the "group" number, how would you load this ?
                  >
                  If fortran90 you would just do:
                  >
                  do 10 k=1,2
                  do 20 i=1,3
                  >
                  read(*,*)(a(i,j ,k),j=1,3)
                  >
                  20 continue
                  10 continue
                  >
                  How would the python equivalent go ?
                  >
                  2. I've read the help on the next one but I just find it difficult
                  understanding it.
                  I have;
                  a=2.000001
                  b=123456.789
                  c=1234.0001
                  >
                  How do you print them with the same number of decimals ?
                  (eg. 2.000, 123456.789, 1234.000)
                  and how do you print them with the same number of significant
                  decimals?
                  (eg. 2.000001, 123456.7, 1234.000 - always 8 decimals) ?
                  >
                  >
                  Is something like this possible (built-in) in python ?
                  >
                  Really grateful for all the help and time you can spare.
                  >
                  --
                  Ivan

                  I'm not sure if this is applicable to your multi-dimensional list
                  problem... but it sounded a bit sudoku like (with row, columns and
                  groups) so I thought I'd share a bit of code of developed in regards to
                  solving sudoku puzzles...

                  Given a list of 9 list elements, each with nine elements (lets call it
                  sudoku_grid), the following list comprehensions produce lists of indexes
                  into sudoku grid

                  vgroups = [[(x,y) for y in xrange(9)] for x in xrange(9)]
                  hgroups = [[(x,y) for x in xrange(9)] for y in xrange(9)]
                  lgroups = [[(x,y) for x in xrange(a,a+3) for y in xrange(b,b+3)]
                  for a in xrange(0,9,3) for b in xrange(0,9,3)]

                  where sudoku_grid[y][x] yields the value at position (x,y), assuming the
                  top left corner is indexed as (0,0)

                  HTH

                  Comment

                  • Ivan Reborin

                    #10
                    Re: Python arrays and sting formatting options

                    On 30 Sep 2008 07:07:52 GMT, Marc 'BlackJack' Rintsch <bj_666@gmx.net >
                    wrote:

                    Hello Marc, thanks for answering (on both subjects). I understand now
                    the logic which lays behind what you were explaining in the other one.
                    It cleared things quite a bit.
                    >Well, I don't know if this qualifies as equivalent:
                    >
                    >=====
                    >from __future__ import with_statement
                    >from functools import partial
                    >from itertools import islice
                    >from pprint import pprint
                    >
                    >
                    >def read_group(line s, count):
                    return [map(int, s.split()) for s in islice(lines, count)]
                    >
                    >def main():
                    result = list()
                    with open('test.txt' ) as lines:
                    lines = (line for line in lines if line.strip())
                    result = list(iter(parti al(read_group, lines, 3), list()))
                    pprint(result, width=30)
                    >if __name__ == '__main__':
                    main()
                    >=====
                    I'm afraid I must admit I find the code above totally uncomprehesible
                    (I can't even see where the array here is mentioned - "result"?) and
                    inpractical for any kind of engineering practice I had in mind.

                    Does python, perchance, have some wrapper functions or something,
                    which would allow one to load an array in a more natural "technical"
                    way ? Like something mentioned above in my post (now deleted) ?

                    Also, is there a way to change counter for arrays to go from 0 to 1 ?
                    (first element being with the index 1) ?
                    (probably not since that seems like a language implementation thing,
                    but it doesn't hurt to ask)

                    --
                    Ivan

                    Comment

                    • Marc 'BlackJack' Rintsch

                      #11
                      Re: Python arrays and sting formatting options

                      On Tue, 30 Sep 2008 15:42:58 +0200, Ivan Reborin wrote:
                      On 30 Sep 2008 07:07:52 GMT, Marc 'BlackJack' Rintsch <bj_666@gmx.net >
                      wrote:
                      >>=====
                      >>from __future__ import with_statement from functools import partial
                      >>from itertools import islice
                      >>from pprint import pprint
                      >>
                      >>
                      >>def read_group(line s, count):
                      > return [map(int, s.split()) for s in islice(lines, count)]
                      >>
                      >>def main():
                      > with open('test.txt' ) as lines:
                      > lines = (line for line in lines if line.strip())
                      > result = list(iter(parti al(read_group, lines, 3), list()))
                      > pprint(result, width=30)
                      >>
                      >>if __name__ == '__main__':
                      > main()
                      >>=====
                      >
                      I'm afraid I must admit I find the code above totally uncomprehesible (I
                      can't even see where the array here is mentioned - "result"?) and
                      inpractical for any kind of engineering practice I had in mind.
                      Learn Python then to understand that code. ;-)

                      There is no array. The data type is called "list" in Python, so `result`
                      is a nested list. And in Python it quite unusual to build lists by
                      creating them with the final size filled with place holder objects and
                      then fill the real values in. Instead lists are typically created by
                      appending values to existing lists, using list comprehension or the
                      `list()` function with some iterable object.

                      Typical Python code tries to minimize the use of index variables. Python
                      is not Fortran (or C, or Pascal, …).
                      Does python, perchance, have some wrapper functions or something, which
                      would allow one to load an array in a more natural "technical" way ?
                      Like something mentioned above in my post (now deleted) ?
                      >
                      Also, is there a way to change counter for arrays to go from 0 to 1 ?
                      You can write your own sequence type but that would be odd because the
                      rest of the language expects zero as the first index, so you will be
                      constantly fighting the language by adding or subtracting 1 all the time
                      at the "border" between your custom sequence type and the the rest of
                      Python.

                      Ciao,
                      Marc 'BlackJack' Rintsch

                      Comment

                      • Peter Pearson

                        #12
                        Re: Python arrays and sting formatting options

                        On Tue, 30 Sep 2008 00:04:18 +0200, Ivan Rebori wrote:
                        >
                        1. Multi dimensional arrays - how do you load them in python
                        For example, if I had:
                        -------
                        1 2 3
                        4 5 6
                        7 8 9
                        >
                        10 11 12
                        13 14 15
                        16 17 18
                        -------
                        with "i" being the row number, "j" the column number, and "k" the ..
                        uhmm, well, the "group" number, how would you load this ?
                        >
                        If fortran90 you would just do:
                        >
                        do 10 k=1,2
                        do 20 i=1,3
                        >
                        read(*,*)(a(i,j ,k),j=1,3)
                        >
                        20 continue
                        10 continue
                        >
                        How would the python equivalent go ?
                        Since you're coming from the FORTRAN world (thank you for
                        that stroll down Memory Lane), you might be doing scientific
                        computations, and so might be interested in the SciPy
                        package (Google scipy), which gives you arrays and matrices.
                        Don't expect to be able to use it without learning some Python,
                        though.

                        --
                        To email me, substitute nowhere->spamcop, invalid->net.

                        Comment

                        • Grant Edwards

                          #13
                          Re: Python arrays and sting formatting options

                          On 2008-09-30, Peter Pearson <ppearson@nowhe re.invalidwrote :
                          On Tue, 30 Sep 2008 00:04:18 +0200, Ivan Rebori wrote:
                          >>
                          >1. Multi dimensional arrays - how do you load them in python
                          >For example, if I had:
                          >-------
                          >1 2 3
                          >4 5 6
                          >7 8 9
                          >>
                          >10 11 12
                          >13 14 15
                          >16 17 18
                          >-------
                          >with "i" being the row number, "j" the column number, and "k" the ..
                          >uhmm, well, the "group" number, how would you load this ?
                          >>
                          >If fortran90 you would just do:
                          >>
                          >do 10 k=1,2
                          >do 20 i=1,3
                          >>
                          >read(*,*)(a(i, j,k),j=1,3)
                          >>
                          >20 continue
                          >10 continue
                          >>
                          >How would the python equivalent go ?
                          You would drag yourself out of the 1960s, install numpy, and
                          then do something like this:

                          a = read_array(open ("filename.dat" ,"r"))
                          Since you're coming from the FORTRAN world (thank you for that
                          stroll down Memory Lane), you might be doing scientific
                          computations, and so might be interested in the SciPy package
                          (Google scipy), which gives you arrays and matrices. Don't
                          expect to be able to use it without learning some Python,
                          though.
                          If not full-up scipy (which provides all sorts of scientific
                          and numerical-analysis stuff), then at least numpy (which
                          provides the basic array/matrix operations:



                          Though the software is free, the documentation isn't. You've
                          got to buy the book if you want something to read. IMO, it's
                          definitely worth it, and a good way to support the project even
                          if you don't really need something to keep your bookends apart.

                          Scientific Python is something else the OP might be interested
                          in. Yes, Scientific Python is different than SciPy:



                          If you're a Windows user, I can recommend the Enthough Python
                          distribution. It has all sorts of numerical and scientific
                          "batteries included".



                          It includes both scipy and scientific python as well as several
                          options for data visualization (e.g. matplotlib, VTK).

                          There's also an Enthought Python distro for Linux, but I've
                          never tried it. I run Gentoo Linux, and there are standard
                          ebuilds for pretty much all of the stuff in EPD.

                          --
                          Grant Edwards grante Yow! I've read SEVEN
                          at MILLION books!!
                          visi.com

                          Comment

                          • Marc 'BlackJack' Rintsch

                            #14
                            Re: Python arrays and sting formatting options

                            On Tue, 30 Sep 2008 10:57:19 -0500, Grant Edwards wrote:
                            On 2008-09-30, Peter Pearson <ppearson@nowhe re.invalidwrote :
                            >On Tue, 30 Sep 2008 00:04:18 +0200, Ivan Rebori wrote:
                            >>>
                            >>1. Multi dimensional arrays - how do you load them in python For
                            >>example, if I had:
                            >>-------
                            >>1 2 3
                            >>4 5 6
                            >>7 8 9
                            >>>
                            >>10 11 12
                            >>13 14 15
                            >>16 17 18
                            >>-------
                            >>with "i" being the row number, "j" the column number, and "k" the ..
                            >>uhmm, well, the "group" number, how would you load this ?
                            >>>
                            >>If fortran90 you would just do:
                            >>>
                            >>do 10 k=1,2
                            >>do 20 i=1,3
                            >>>
                            >>read(*,*)(a(i ,j,k),j=1,3)
                            >>>
                            >>20 continue
                            >>10 continue
                            >>>
                            >>How would the python equivalent go ?
                            >
                            You would drag yourself out of the 1960s, install numpy, and then do
                            something like this:
                            >
                            a = read_array(open ("filename.dat" ,"r"))
                            In [64]: a = numpy.fromfile( 'test.txt', dtype=int, sep=' ')

                            In [65]: a
                            Out[65]:
                            array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
                            18])

                            In [66]: a.reshape(2, 3, 3)
                            Out[66]:
                            array([[[ 1, 2, 3],
                            [ 4, 5, 6],
                            [ 7, 8, 9]],

                            [[10, 11, 12],
                            [13, 14, 15],
                            [16, 17, 18]]])

                            Ciao,
                            Marc 'BlackJack' Rintsch

                            Comment

                            • Ivan Reborin

                              #15
                              Re: Python arrays and sting formatting options

                              On 30 Sep 2008 15:31:59 GMT, Peter Pearson <ppearson@nowhe re.invalid>
                              wrote:
                              >
                              >Since you're coming from the FORTRAN world (thank you for
                              >that stroll down Memory Lane), you might be doing scientific
                              >computations , and so might be interested in the SciPy
                              >package (Google scipy), which gives you arrays and matrices.
                              >Don't expect to be able to use it without learning some Python,
                              >though.
                              Actually, no (regarding memory lane :-). I'm helping a friend to
                              translate some of my old routines to python so he can use them in his
                              programs.
                              I'm still using fortran84, and mean to continue doing so as long as
                              something better doesn't come along.

                              But as I said, got a job that't got to be done, so I'm trying to
                              figure out how to do array operations as easily as possible in python,
                              which are necessary for all my calculations.

                              Best regards
                              Ivan

                              Comment

                              Working...