How concatenate 2 Numpy array efficiently?

Arefe

I have 2 Numpy array <type 'numpy.ndarray'> with shape of (10,) (10, 6) and I would like to concat the first one with the second. The numpy array provided below,

r1 
['467c8100-7f13-4244-81ee-5e2a0f8218a8',
 '71a4b5b2-80d6-4c12-912f-fc71be8d923e',
 '7a3e0168-e47d-4203-98f2-a54a46c62ae0',
 '7dfd43e7-ced1-435f-a0f9-80cfd00ae246',
 '85dbc70e-c773-43ee-b434-8f458d295d10',
 'a56b2bc3-4a81-469e-bc5f-b3aaa520db05',
 'a9e8996f-ff35-4bfb-bbd9-ede5ffecd4d8',
 'c3037410-0c2e-40f8-a844-ac0664a05783',
 'c5618563-10c0-425b-a11b-2fcf931f0ff7',
 'f65e6cea-892e-4335-8e86-bf7f083b5f53'] 

r2 
[[1.55000000e+02, 5.74151515e-01, 1.55000000e+02, 5.74151515e-01, 3.49000000e+02, 1.88383585e+00],
 [5.00000000e+00, 1.91871554e-01, 1.03000000e+02, 1.22893828e+00, 2.95000000e+02, 3.21148368e+00],
 [7.10000000e+01, 1.15231270e-01, 2.42000000e+02, 5.78527276e-01, 4.09000000e+02, 2.67915246e+00],
 [3.60000000e+01, 7.10066720e-01, 2.42000000e+02, 1.80213634e+00, 4.12000000e+02, 4.16314391e+00],
 [1.15000000e+02, 1.05120284e+00, 1.30000000e+02, 1.71697773e+00, 2.53000000e+02, 2.73640301e+00],
 [4.70000000e+01, 2.19434656e-01, 3.23000000e+02, 4.84093786e+00, 5.75000000e+02, 7.00530186e+00],
 [5.50000000e+01, 1.22614463e+00, 1.04000000e+02, 1.55392099e+00, 4.34000000e+02, 4.13661261e+00],
 [3.90000000e+01, 3.34816889e-02, 1.10000000e+02, 2.54431753e-01, 2.76000000e+02, 1.52322736e+00],
 [3.43000000e+02, 2.93550948e+00, 5.84000000e+02, 5.27968165e+00, 7.45000000e+02, 7.57657633e+00],
 [1.66000000e+02, 1.01436635e+00, 2.63000000e+02, 2.69197514e+00, 8.13000000e+02, 7.96477735e+00]]

I tried to concatenate with the command np.concatenate((r1, r2)), it returns with the message of ValueError: all the input arrays must have same number of dimensions which I don't understand. Because, the r1 can possibly concat with the r2 and can form a whole new array and make a new array of 10 x 7 as result.

How to solve this problem ?

mdh

You can reshape r1 to make it two-dimensional and specify the axis along which the arrays should be joined:

import numpy as np

r1 = np.ones((10,))
r2 = np.zeros((10, 6))
np.concatenate((r1.reshape(10, 1), r2), axis=1)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to efficiently concatenate strings in go

From Dev

How to efficiently concatenate many arange calls in numpy?

From Dev

How to check efficiently if numpy array a contains b

From Dev

How to efficiently output n items per line from numpy array

From Dev

Efficiently select subsection of numpy array

From Dev

How to efficiently turn a boolean numpy array into threshold boolean array?

From Dev

How to extract a list of elements given by their indices from a numpy array efficiently?

From Dev

Numpy concatenate 2D arrays with 1D array

From Dev

How to extract a sub-array in numpy efficiently?

From Dev

copy numpy array efficiently

From Dev

How to make a large numpy array efficiently

From Dev

How to efficiently shuffle numpy array in chunks

From Dev

Concatenate a tuple with a value that is on a numpy array

From Dev

How to concatenate an empty array with Numpy.concatenate?

From Dev

How to merge 2 numpy arrays and concatenate their values?

From Dev

Efficiently convert gmpy2.mpz to numpy boolean array

From Dev

Fail to concatenate two numpy array

From Dev

How to concatenate efficiently a list of dataframes?

From Dev

How to efficiently iterate a pandas DataFrame and increment a NumPy array on these values?

From Dev

How do you efficiently repeat a 2D numpy array with an offset?

From Dev

How to efficiently concatenate many arange calls in numpy?

From Dev

Efficiently convert gmpy2.mpz to numpy boolean array

From Dev

Append/concatenate Numpy array to Numpy array

From Dev

How can I concatenate a list of 2d numpy arrays into a 3d numpy array?

From Dev

Modifying a numpy array efficiently

From Dev

Concatenate strings from a 2D numpy array

From Dev

Unsure how to concatenate each numpy array within a list

From Dev

Concatenate elements of an array with numpy?

From Dev

Numpy array: efficiently assign values

Related Related

  1. 1

    How to efficiently concatenate strings in go

  2. 2

    How to efficiently concatenate many arange calls in numpy?

  3. 3

    How to check efficiently if numpy array a contains b

  4. 4

    How to efficiently output n items per line from numpy array

  5. 5

    Efficiently select subsection of numpy array

  6. 6

    How to efficiently turn a boolean numpy array into threshold boolean array?

  7. 7

    How to extract a list of elements given by their indices from a numpy array efficiently?

  8. 8

    Numpy concatenate 2D arrays with 1D array

  9. 9

    How to extract a sub-array in numpy efficiently?

  10. 10

    copy numpy array efficiently

  11. 11

    How to make a large numpy array efficiently

  12. 12

    How to efficiently shuffle numpy array in chunks

  13. 13

    Concatenate a tuple with a value that is on a numpy array

  14. 14

    How to concatenate an empty array with Numpy.concatenate?

  15. 15

    How to merge 2 numpy arrays and concatenate their values?

  16. 16

    Efficiently convert gmpy2.mpz to numpy boolean array

  17. 17

    Fail to concatenate two numpy array

  18. 18

    How to concatenate efficiently a list of dataframes?

  19. 19

    How to efficiently iterate a pandas DataFrame and increment a NumPy array on these values?

  20. 20

    How do you efficiently repeat a 2D numpy array with an offset?

  21. 21

    How to efficiently concatenate many arange calls in numpy?

  22. 22

    Efficiently convert gmpy2.mpz to numpy boolean array

  23. 23

    Append/concatenate Numpy array to Numpy array

  24. 24

    How can I concatenate a list of 2d numpy arrays into a 3d numpy array?

  25. 25

    Modifying a numpy array efficiently

  26. 26

    Concatenate strings from a 2D numpy array

  27. 27

    Unsure how to concatenate each numpy array within a list

  28. 28

    Concatenate elements of an array with numpy?

  29. 29

    Numpy array: efficiently assign values

HotTag

Archive