Search code examples
arraysnumpytuplesfusionor-operator

Merge tuples and numpy arrays


I would like to know how to turn some tuples with numpy arrays containing different numbers, into a unique tuple, with just an array, containing all the numbers. For example:

a=(array([0,11]),) 
b=(array([12]),) 
c=merge(a,b)=(array([0,11,12]),)

Could someone help me? I am still not used to numpy... a and b were found using numpy.where() and display exactly as written up there. I tried this, but did not work:

c=a or b

Thanks a lot for helping me ! :)


Solution

  • def merg():
        a=(np.array([0,11]),) 
        b=(np.array([12]),)
        return tuple(np.hstack([a,b]))
    

    Results:

    >>> merg()
    (array([ 0, 11, 12]),)