# numpy/numpy-dtypes

1 parent b6f1a9a commit 66b20fe11a7f212fb1a2a2e4137e06c94fdf8e08 jayvius@gmail.com committed Jun 27, 2012
Showing with 76 additions and 0 deletions.
1. +22 −0 doc/extendingufunc.rst
2. +34 −0 doc/newgufunc.rst
3. +20 −0 doc/newufunc.rst
22 doc/extendingufunc.rst
 @@ -125,4 +125,26 @@ object representing the sum of those two rational numbers:: REGISTER_UFUNC_BINARY_RATIONAL(add) + | + +An example of using the add ufunc with the Rational dtype:: + + In [1]: import numpy as np + + In [2]: from rational import rational + + In [3]: r1=rational(1,2) + + In [4]: r2=rational(3,4) + + In [5]: r3=rational(5,6) + + In [6]: r4=rational(7,8) + + In [7]: a=np.array([r1,r2], dtype=rational) + + In [8]: b=np.array([r3,r4], dtype=rational) + + In [9]: np.add(a,b) + Out[9]: array([4/3, 13/8], dtype=rational)
34 doc/newgufunc.rst
 @@ -102,4 +102,38 @@ vectors or matrices and performs a matrix multiply on each pair of matrix elemen PyModule_AddObject(m,"matrix_multiply",(PyObject*)gufunc); + | + +An example of using the add ufunc with the Rational dtype:: + + In [1]: import numpy as np + + In [2]: from rational import rational, matrix_multiply + + In [3]: r1=rational(1,2) + + In [4]: r2=rational(3,4) + + In [5]: r3=rational(5,6) + + In [6]: r4=rational(7,8) + + In [7]: a=np.array([[[[r1,r2],[r3,r4]],[[r1,r2],[r3,r4]]], [[[r1,r2],[r3,r4]],[[r1,r2],[r3,r4]]]], dtype=rational) + + In [8]: b=np.array([[[[r3,r4],[r1,r2]],[[r3,r4],[r1,r2]]], [[[r3,r4],[r1,r2]],[[r3,r4],[r1,r2]]]], dtype=rational) + + In [9]: matrix_multiply(a,b) + Out[9]: + array([[[[19/24, 1], + [163/144, 133/96]], + + [[19/24, 1], + [163/144, 133/96]]], + + + [[[19/24, 1], + [163/144, 133/96]], + + [[19/24, 1], + [163/144, 133/96]]]], dtype=rational)
20 doc/newufunc.rst
 @@ -96,4 +96,24 @@ values based rational numbers from the input array. NEW_UNARY_UFUNC(numerator,NPY_INT64,"rational number numerator"); + | + +An example of using the numerator ufunc with the Rational dtype:: + + In [1]: import numpy as np + + In [2]: from rational import rational, numerator + + In [3]: r1=rational(1,2) + + In [4]: r2=rational(3,4) + + In [5]: r3=rational(5,6) + + In [6]: r4=rational(7,8) + + In [7]: a=np.array([r1,r2,r3,r4], dtype=rational) + + In [8]: numerator(a) + Out[8]: array([1, 3, 5, 7])