'How to store to an array after adding multiple column in a specific location in the array using for loop

I am trying to add multiple columns in an array by giving specific location. So I thought to use for loop. And make a list of indexes. But it is only adding the last index to the array. It is not avail to store. I have to add columns with Nan value to many specific location of the array. This is just small instance of the code. If there is any other way to solve the problem please let me know.

This is my code:

array=np.empty(\[6,1\])
array.fill(np.nan)

lst=\[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21\]
for i in lst:
    target=np.column_stack((spect\[:,:i\],array,spect\[:,i:\]))

    print (target)
target.shape

result:

\[\[0.0915992  0.09395572 0.09608554 ... 0.31121245 0.30788592 0.30448991\]
\[0.09066667 0.09376317 0.09546562 ... 0.31083897 0.31072924 0.30172387\]
\[0.09106574 0.09336292 0.09486577 ... 0.30112922 0.29567787 0.29520443\]
\[0.06598862 0.06569809 0.06667278 ... 0.05683024 0.05461031 0.05219743\]
\[0.0662761  0.06652138 0.06710701 ... 0.05841261 0.05783615 0.05895313\]
\[0.09810975 0.10111948 0.10372283 ... 0.28055483 0.27715871 0.27280515\]\]
(6, 261)

I am excepting target.shape (6,282) with adding 22 to columns.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source