Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 keep only one tuple between 2
#1
Hi

I've 2 tuples (coming from numpy.where) which one is necessary empty:
a = tuple1
b = tuple2

In one sentence, I'm wondering how can I keep the one that is not empty?

For example, I had a look to 'numpy.any' that give me back 'True' or 'False', but I'm not able to go further.

Thanks for your help

Paul
Quote
#2
There is lot of ambiguity here but tuples are compared lexicographically and booleans 'and' and 'or' return one of their operands. So one can do:

>>> a, b = (), (0,)                                                                       
>>> a < b and b or a                                                                      
(0,)
>>> a, b = (0,), ()                                                                       
>>> a < b and b or a                                                                      
(0,)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Quote
#3
Hi perfringo

Thanks for your answer; based on your example, I did some tests to understand how it works and it helped me a lot

Paul

import numpy as np

# my tupples
a = ( 0, 15, 49, 100, 1568)
b = ()

# 1rst (splitted) solution
result  = (a < b and b) or a
c  = a < b
d = a < b and b
e = a < b or a

# another one
f = (np.any(a))*a or (np.any(b)*b) # being deprecated
f = ((np.any(a)).astype(int))*a + ((np.any(b)).astype(int))*b
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)