AKKYM
@AKKYM

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

【Python】numpyを使って配列に一個飛ばしで数を挿入する方法。

Q&A

Closed

>>> import numpy as np
>>> a = np.array([1,2,3,4])
>>> func(a, 0)
array([1, 0, 2, 0, 3, 0, 4, 0])

これをなるべく短くしたいです。

0

4Answer

def func(a, v):
    out = np.full(a.size*2, v, dtype=a.dtype)
    out[::2] = a
    return out

はやい(短くはない)。

1Like

Your answer might help someone💌