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. 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
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.
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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;...
|
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...
|
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...
|
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 =...
|
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 =...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |