473,396 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

doucmentation bug or bug? p or q for numerical arrays

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/...tm#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.
Jul 18 '05 #1
3 1228
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/...tm#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

Jul 18 '05 #2
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/...tm#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.

Jul 18 '05 #3

"Peter Otten" <__*******@web.de> wrote in message
news:ce*************@news.t-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

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: 2mc | last post by:
I'm new to Python and to Numerical Python. I have a program written in another program that used arrays extensively. I'm trying to convert to Python. Assume an array in Numerical Python, the...
14
by: 2mc | last post by:
Generally speaking, if one had a list (from regular Python) and an array (from Numerical Python) that contained the same number of elements, would a While loop or a For loop process them at the...
5
by: mma | last post by:
I have been using the lubksb routine in Visual C++ 6.0 and noticed what looks like an error to me. The last section of the method looks like this: for(i=n;i>=1;i--) { sum=b;...
5
by: Edward Hua | last post by:
Hi, I'm wondering if anybody has ever copied the quicksort algorithm from the book Numerical Recipes in C: The Art of Scientific Computing (2nd ed.), by Press, Teukolsky, Vetterling, and...
11
by: lcw1964 | last post by:
Greetings groups! I am a rank novice in both C programming and numerical analysis, so I ask in advance your indulgence. Also, this question is directed specifically to those familiar with Numerical...
2
by: farah727rash | last post by:
Hi all, I am trying to find the numerical value of a string that stores a two digit number. I have found the numerical value of a char as: char character; cin >> character; int number =...
8
by: farah727rash | last post by:
Hi all, I am trying to find the numerical value of a string that stores a two digit number. I have found the numerical value of a char as: char character; cin >character; int number =...
10
by: Babak | last post by:
Hi, I've developed a C program which contains a large number of vectors and matrices operations. Throughout my code, I used the template from the Numerical Recipes book to define vectors and...
30
by: Ivan Reborin | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.