0

Is there a function in python that allows me to insert number 100's or consecutive non zeros in the array [1,2,3,4,5]?

Output should be [1, 100, 100, 100, 2, 100, 100, 100, 3 .....] or [ 1, 100, 101, 102, 2 , 100, 101, 102, 3...]

I have tried numpy.insert()

ar2=np.insert(ar1, slice(1,None), range(100,103))

Output: array([ 1, 100, 2, 101, 3, 102, 4, 100, 5, 101])

Numpy.Insert() method allows addition of only a single number between the input elements. Let me know your thoughts on this.

1

1 Answer 1

0

You can use numpy.kron

np.kron([1,2,3,4,5],[1,0,0,0]) + 100*np.kron(np.ones(5),[0,1,1,1])

for the second one

np.kron([1,2,3,4,5],[1,0,0,0]) + np.kron(np.ones(5),[0,101,102,103])
Sign up to request clarification or add additional context in comments.

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.