[Numpy-discussion] Using logical function on more than 2 arrays, availability of a "between" function ?
Mon Mar 19 08:20:23 CDT 2012
What do you mean by "efficient"? Are you trying to get it execute
faster? Or using less memory? Or have more concise source code?
- numpy.vectorize would let you get to the end result without any
intermediate arrays but will be slow.
- Using the "out" parameter of numpy.logical_and will let you avoid
one of the intermediate arrays.
Perhaps putting all three boolean temporary results into a single
boolean array (using the "out" parameter of numpy.greater, etc) and
using numpy.all might benefit from logical short-circuiting.
And watch out for divide-by-zero from "aNirChannel/aBlueChannel".
On 19 March 2012 11:04, Matthieu Rigal <email@example.com> wrote:
> Dear Numpy fellows,
> I have actually a double question, which only aims to answer a single one :
> how to get the following line being processed more efficiently :
> array = numpy.logical_and(numpy.logical_and(aBlueChannel < 1.0, aNirChannel >
> (aBlueChannel * 1.0)), aNirChannel < (aBlueChannel * 1.8))
> One possibility would have been to have the logical_and being able to handle
> more than two arrays
> Another one would have been to be able to make a "double comparison" or a
> "between", like following one :
> array = numpy.logical_and((aBlueChannel < 1.0), (1.0 <
> aNirChannel/aBlueChannel < 1.8))
> Is there any way to get the things work this way ? Would it else be a possible
> improvement for 1.7 or a later version ?
> Best Regards,
> Matthieu Rigal
> RapidEye AG
> Molkenmarkt 30
> 14776 Brandenburg an der Havel
> Follow us on Twitter! www.twitter.com/rapideye_ag
> Head Office/Sitz der Gesellschaft: Brandenburg an der Havel
> Management Board/Vorstand: Ryan Johnson
> Chairman of Supervisory Board/Vorsitzender des Aufsichtsrates:
> Robert Johnson
> Commercial Register/Handelsregister Potsdam HRB 24742 P
> Tax Number/Steuernummer: 048/100/00053
> VAT-Ident-Number/Ust.-ID: DE 199331235
> DIN EN ISO 9001 certified
> NumPy-Discussion mailing list
More information about the NumPy-Discussion