doucmentation bug or bug? p or q for numerical arrays

Discussion in 'Python' started by Alan G Isaac, Jul 29, 2004.

  1. Alan G Isaac

    Alan G Isaac Guest

    from Numeric import *
    p = array([1, 1, 0, 0])
    q = array([1, 0, 1, 0])
    print logical_or(p,q) #expected result
    print (p or q) #prints p

    This might be expected, except for the documentation:
    http://numpy.sourceforge.net/numdoc/HTML/numdoc.htm#pgfId-36127

    "Universal Functions, or ufunc s. The operators which invoke them when
    applied to arrays are indicated in parentheses."

    And then numarray has the same documentation (in the manual)
    but chokes altogether on the use of 'or'.

    There is a like problem with 'and'.

    Am I misreading something?
    Are there actually operators for these functions?

    Thanks,
    Alan Isaac

    PS A comment: operators are really useful here. Using the ufuncs
    makes for very messy code. See the GAUSS programming
    language for a nice syntax.
     
    Alan G Isaac, Jul 29, 2004
    #1
    1. Advertising

  2. Alan G Isaac

    Peter Otten Guest

    Alan G Isaac wrote:

    > from Numeric import *
    > p = array([1, 1, 0, 0])
    > q = array([1, 0, 1, 0])
    > print logical_or(p,q) #expected result
    > print (p or q) #prints p
    >
    > This might be expected, except for the documentation:
    > http://numpy.sourceforge.net/numdoc/HTML/numdoc.htm#pgfId-36127
    >
    > "Universal Functions, or ufunc s. The operators which invoke them when
    > applied to arrays are indicated in parentheses."
    >
    > And then numarray has the same documentation (in the manual)
    > but chokes altogether on the use of 'or'.
    >
    > There is a like problem with 'and'.
    >
    > Am I misreading something?
    > Are there actually operators for these functions?


    Unlike '&', '|' and '~', the logical operators 'and' and 'or' cannot be
    overridden, 'not' not in a useful manner (__nonzero__() must return an
    integer). The documentation is probably wrong.

    Peter
     
    Peter Otten, Jul 29, 2004
    #2
    1. Advertising

  3. Peter Otten wrote:
    > Alan G Isaac wrote:
    >
    >
    >>from Numeric import *
    >>p = array([1, 1, 0, 0])
    >>q = array([1, 0, 1, 0])
    >>print logical_or(p,q) #expected result
    >>print (p or q) #prints p
    >>
    >>This might be expected, except for the documentation:
    >> http://numpy.sourceforge.net/numdoc/HTML/numdoc.htm#pgfId-36127
    >>
    >>"Universal Functions, or ufunc s. The operators which invoke them when
    >>applied to arrays are indicated in parentheses."
    >>
    >>And then numarray has the same documentation (in the manual)
    >>but chokes altogether on the use of 'or'.
    >>
    >>There is a like problem with 'and'.
    >>
    >>Am I misreading something?
    >>Are there actually operators for these functions?

    >
    >
    > Unlike '&', '|' and '~', the logical operators 'and' and 'or' cannot be
    > overridden, 'not' not in a useful manner (__nonzero__() must return an
    > integer). The documentation is probably wrong.
    >
    > Peter
    >

    The not yet released version of PyMatrix, which subsclasses NumArray,
    behaves as follows:

    import PyMatrix.matrix as _m
    p = _m.M([1, 1, 0, 0], type= _m._nt.Bool)
    q = _m.M([1, 0, 1, 0], type= _m._nt.Bool)
    print p ^ q # -> [[F T T F]]
    print p & q # -> [[T F F F]]
    print p | q # -> [[T T T F]]

    Colin W.
     
    Colin J. Williams, Jul 29, 2004
    #3
  4. Alan G Isaac

    Terry Reedy Guest

    "Peter Otten" <> wrote in message
    news:cea2mh$5u5$04$-online.com...
    > Unlike '&', '|' and '~', the logical operators 'and' and 'or' cannot be
    > overridden,


    Which is because they are not actually operators in the strict sense (in
    which 'a op b' is short for 'opfunc(a,b)'). Because of their
    'short-circuiting' behavior, they are 'special forms' (in the Lisp sense)
    that may not calculate b, whereas a function call always would. The
    so-called ternary op is also special and also can not be directly written
    as a function for the same reason.

    Terry J. Reedy
     
    Terry Reedy, Jul 30, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. iMonkey

    Numerical Order

    iMonkey, Jul 31, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    386
    iMonkey
    Jul 31, 2003
  2. Al Murphy

    Java numerical recipes online...

    Al Murphy, Feb 5, 2004, in forum: Java
    Replies:
    1
    Views:
    5,672
    Steve W. Jackson
    Feb 5, 2004
  3. MrMF

    Numerical Integration of 2D data arrays

    MrMF, Nov 7, 2008, in forum: C Programming
    Replies:
    0
    Views:
    1,813
  4. Philipp
    Replies:
    21
    Views:
    1,184
    Philipp
    Jan 20, 2009
  5. M. R.

    libnet doucmentation

    M. R., Oct 15, 2007, in forum: Ruby
    Replies:
    2
    Views:
    103
    Frank Hale
    Oct 16, 2007
Loading...

Share This Page