Fill array with NaNs

Bruno Luong el 28 de Oct. de 2024 (Editada a las el 28 de Oct. de 2024)
Actividad más reciente Edición por Bruno Luong a las el 28 de Oct. de 2024

Time to time I need to filll an existing array with NaNs using logical indexing. A trick I discover is using arithmetics rather than filling. It is quite faster in some circumtances
A=rand(10000);
b=A>0.5;
tic; A(b) = NaN; toc
Elapsed time is 0.737291 seconds.
tic; A = A + 0./~b; toc;
Elapsed time is 0.027666 seconds.
If you know trick for other value filling feel free to post.
goc3
goc3 el 28 de Oct. de 2024
That is a clever trick.
Chen Lin
Chen Lin el 28 de Oct. de 2024
Thanks for sharing this quick trick, Bruno. This marks your first post and we look forward to seeing more.
Bruno Luong
1
Publicación
265
Responder

Etiquetas

Aún no se han introducido etiquetas.