[AstroPy] Short survey on behavior of multi-dimensional arrays

Steve Spicklemire steve at spvi.com
Fri Mar 2 09:30:09 CST 2001


Hi Paul,

>>>>> "Paul" == Paul Barrett <Barrett at stsci.edu> writes:

    Paul>                              Questionaire

    Paul> Q1. Given the following Python code:

    >>> A = array([11, 12, 13])
    >>> B = A[:]
    >>> A[0] = 1

    Paul>     What is B[0] and why?

B[0] is 1. Since you didn't 'copy' the array, the slice makes a new list
with references to the original data. I think Numeric is conservative this way
to minimize memory use when dealing with large slices on large arrays
where you really just want to have a new 'coordinate' system, but don't need
a separate copy of the array. If you want a separate copy.. use 'copy = 1'.

    Paul> Q2. Given the following Python code:

    >>> A = array([[11, 12, 13], [21, 22, 23], [31, 32, 33]])
    >>> B = A[0]
    >>> A[0] = [1, 2, 3]

    Paul>     Again, what is B[0] and why?

B[0] is 1. Same reason.

    Paul> Q3. Given the following Python code:

    >>> A = array([11.0, 12.0, 13.0], Float32)
    >>> B = 2.0*A

I think this was the cause of *much* debate, but the result
is a 'd' array rather than the expected 'f' array. I think the
idea here was to promote to the higher precision unless both
objects involved were the same precision.

-steve

    Paul>     What type is B and why?

    Paul>     (Note that real numbers in Python are internally stored
    Paul> as double precision floating-point numbers.)

    Paul> ------------------------------------------------------------------------

    Paul> -- Dr. Paul Barrett Space Telescope Science Institute Phone:
    Paul> 410-338-4475 ESS/Science Software Group FAX: 410-338-4767
    Paul> Baltimore, MD 21218
    Paul> _____________________________________________________
    Paul> AstroPy mailing list - astropy at stsci.edu
    Paul> http://lheawww.gsfc.nasa.gov/~bridgman/AstroPy/


This is a short survey on some behavioral aspects of multi-dimensional
arrays.  Please take the time to complete this survey and send your
results back to me: Paul Barrett <barrett at stsci.edu>.  Please don't
hesitate to contact me if you need clarification on one or more
questions or have questions of your own that you would like answered.

Cheers,
Paul

------------------------------------------------------------------------

                             Questionaire

Q1. Given the following Python code:

    >>> A = array([11, 12, 13])
    >>> B = A[:]
    >>> A[0] = 1

    What is B[0] and why?


Q2. Given the following Python code:

    >>> A = array([[11, 12, 13], [21, 22, 23], [31, 32, 33]])
    >>> B = A[0]
    >>> A[0] = [1, 2, 3]

    Again, what is B[0] and why?


Q3. Given the following Python code:

    >>> A = array([11.0, 12.0, 13.0], Float32)
    >>> B = 2.0*A

    What type is B and why?

    (Note that real numbers in Python are internally stored as double
    precision floating-point numbers.)

------------------------------------------------------------------------

-- 
Dr. Paul Barrett       Space Telescope Science Institute
Phone: 410-338-4475    ESS/Science Software Group
FAX:   410-338-4767    Baltimore, MD 21218
_____________________________________________________
AstroPy mailing list  -  astropy at stsci.edu
http://lheawww.gsfc.nasa.gov/~bridgman/AstroPy/

_____________________________________________________
AstroPy mailing list  -  astropy at stsci.edu
http://lheawww.gsfc.nasa.gov/~bridgman/AstroPy/



More information about the AstroPy mailing list