I want to insert NaN at specific locations in A. However, there is an error. I attach the expected output.
import numpy as np
from numpy import NaN
A = np.array([10, 20, 30, 40, 50, 60, 70])
C=[2,4]
A=np.insert(A,C,NaN,axis=0)
print("A =",[A])
The error is
<module>
A=np.insert(A,C,NaN,axis=0)
File "<__array_function__ internals>", line 5, in insert
File "C:\Users\USER\anaconda3\lib\site-packages\numpy\lib\function_base.py", line 4678, in insert
new[tuple(slobj)] = values
ValueError: cannot convert float NaN to integer
The expected output is
[array([10, 20, NaN, 30, 40, NaN, 50, 60, 70])]
NANin the integer type. It only exists in the floating type. You cannot convert it to an integer.