1

I have a numpy array :

a= [1,2,3,4,5,6]

I need to do some sort of string multiplication on this array as follows :

2*string(a) = [1,1,2,2,3,3,4,4,5,5,6,6]

Is there any way to do this in numpy?

Thanks

1
  • 3
    Try using np.repeat(a, 2) Commented Jan 10, 2019 at 18:11

2 Answers 2

2

You could use np.repeat:

import numpy as np

a= [1,2,3,4,5,6]
result = np.repeat(a, 2)

print(result)

Output

[1 1 2 2 3 3 4 4 5 5 6 6]
Sign up to request clarification or add additional context in comments.

Comments

1

Use numpy repeat:

a = np.array([1,2,3,4,5,6])
print(np.repeat(a,2))

Which gives:

[1 1 2 2 3 3 4 4 5 5 6 6]

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.