user2858910
user2858910

Reputation: 129

python numpy convert two diffrent dimension arrays to one tuple

I got two arrays, the one is(array A[10][10000]):

 1:   [[   0    0    0 ...,  156  665  621]
 2:    [   0    0    0 ..., -187 -186 -186]
 3:    [   0    0    0 ...,   61  -22  -55]
       ..., 
 8:    [   0    0    0 ...,  540  402  496]
 9:    [   0    0    0 ...,   31   31   33]
10:    [   0    0    0 ..., -525 -504 -492]]

length is 10*10000,type is <type 'numpy.ndarray'> ,and dtype is int16

anothor one is(array B[10]) : b=numpy.arange(10)

[   0    1    2 ..., 7 8 9]

length is 10, type is <type 'numpy.ndarray'>, and dtype is int32

and I wish to convert this two different dimension arrays to one tuple like this(tuple C):

(array([[ 0,  0,  0, ...,  156,  665,  621],
        [ 0,  0,  0, ..., -187, -186,    0],
        [ 0,  0,  0, ...,   61,  -22,  -55],
        ..., 
        [ 0,  0,  0, ...,  540,  402,  496],
        [ 0,  0,  0, ...,   31,   31,   33],
        [ 0,  0,  0, ..., -525, -504, -492]], dtype=int16),
 array( [ 0,  1,  2, ...,    7,    8,    9], dtype=int32))

more information about tuple C:

print A[0].shape = (10, 10000)
print A[0].dtype.name = int16
print type(A[0]) = <type 'numpy.ndarray'>

print A[1].shape  = (10,)
print A[1].dtype.name = int32
print type(A[1]) = <type 'numpy.ndarray'>

Upvotes: 0

Views: 389

Answers (1)

Dave Kirby
Dave Kirby

Reputation: 26572

Unless I am missing something, you just want a tuple with the two arrays as elements:

C = (A, B)

Upvotes: 2

Related Questions