Ticket #11334: trac11334-numpy.rst.patch

File trac11334-numpy.rst.patch, 2.3 KB (added by fbissey, 8 years ago)

first draft at updating the documentation

  • doc/en/numerical_sage/numpy.rst

    # HG changeset patch
    # User Francois Bissey <francois.bissey@canterbury.ac.nz>
    # Date 1326836640 -46800
    # Node ID 8d780ec50b3fa0207163493be3e0f9847629c80d
    # Parent  92c93226b64f933e0af00bbcbd1a8a79c444f43f
    trac 11334: update to numpy-1.6.1 documentation.
    
    diff --git a/doc/en/numerical_sage/numpy.rst b/doc/en/numerical_sage/numpy.rst
    a b  
    2121
    2222NumPy arrays can store any type of python object. However, for speed,
    2323numeric types are automatically converted to native hardware types
    24 (i.e., ``int``, ``float``, etc.) when possible.  If the value or
     24(i.e., ``int``, ``float``, etc.) when possible. This behavior was broken
     25in numpy-1.6 and over, the conversion from sage object depends on the
     26context but most of the time the conversion will have to be done manually
     27to get a native hardware type. If the value or
    2528precision of a number cannot be handled by a native hardware type,
    2629then an array of Sage objects will be created.  You can do
    2730calculations on these arrays, but they may be slower than using native
     
    8689    sage: l[3:6]
    8790    array([ 3.,  4.,  5.])
    8891
    89 You can do basic arithmetic operations
     92You can do basic arithmetic operations, note how the multiplication by a sage scalar
     93is not automatically converted,
    9094
    9195.. link
    9296
     
    9599    sage: l+l
    96100    array([  0.,   2.,   4.,   6.,   8.,  10.,  12.,  14.,  16.,  18.])
    97101    sage: 2.5*l
     102    array([0.000000000000000, 2.50000000000000, 5.00000000000000,
     103           7.50000000000000, 10.0000000000000, 12.5000000000000,
     104           15.0000000000000, 17.5000000000000, 20.0000000000000,
     105           22.5000000000000], dtype=object)
     106    sage: numpy.array(2.5*l,dtype=float)
    98107    array([  0. ,   2.5,   5. ,   7.5,  10. ,  12.5,  15. ,  17.5,  20. ,  22.5])
    99108
    100109Note that ``l*l`` will multiply the elements of ``l`` componentwise. To get
     
    283292    sage: def f(x,y):
    284293    ...       return x**2+y**2
    285294    sage: from numpy import meshgrid
    286     sage: x=numpy.r_[0.0:1.0:5*j]
    287     sage: y=numpy.r_[0.0:1.0:5*j]
     295    sage: x=numpy.array[numpy.r_[0.0:1.0:5*j],dtype=float]
     296    sage: y=numpy.array[numpy.r_[0.0:1.0:5*j],dtype=float]
    288297    sage: xx,yy= meshgrid(x,y)
    289298    sage: xx
    290299    array([[ 0.  ,  0.25,  0.5 ,  0.75,  1.  ],