0

I have a doubt in numpy array concatenation.

For eg,

If I have

a = [ 1, 2, 3]
b = [4, 5, 6, 7]
c= [5, 2]

Could I concatenate arrays of different size??? If so, How could it be possible?

6
  • np.concatenate((a,b,c))? Commented Jan 12, 2017 at 8:09
  • Same way you'd concatenate arrays of the same size. Commented Jan 12, 2017 at 8:18
  • When you say "concatenate", do you mean you want the result to be [1, 2, 3, 4, 5, 6, 7, 5, 2], or do you want to create something like a jagged array using a, b and c for the rows (so the rows have different lengths)? It would help if you could put that information in the question. Commented Jan 12, 2017 at 9:31
  • @WarrenWeckesser, No, I want the result to be: [1,2,3,\n,4,5,6,7\n,5,2] Commented Jan 12, 2017 at 10:18
  • Please add that, along with your comment to Ruhul Amin's answer, to the question. Commented Jan 12, 2017 at 10:28

1 Answer 1

1

Yes, You can using numpy.concatenate

import numpy as np
a = [ 1, 2, 3]
b = [4, 5, 6, 7]
c= [5, 2]
d = np.concatenate((a, b, c))
Sign up to request clarification or add additional context in comments.

2 Comments

My problem is: I want to merge numpy array as a csv file. I used : np.savetxt("output-1.csv", final_array, fmt="%3.2f"). Since"final_array" contains rows of different sizes, it doesnot works
I want the result to be: [1,2,3,\n,4,5,6,7\n,5,2]

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.