Borrar filtros
Borrar filtros

Sparse for arrays with lots of NaN.

19 visualizaciones (últimos 30 días)
Laurent
Laurent el 4 de Sept. de 2013
Editada: Walter Roberson el 4 de Dic. de 2017
Hi,
I am using very large arrays containing a lot fo NaNs. If they were zeros, I could use 'sparse' to save a lot of memory, but since they are NaNs this does not work. Does a sparse datatype exist for arrays with a lot of NaNs?

Respuesta aceptada

Matt J
Matt J el 4 de Sept. de 2013
No, but why do you insist on using NaNs instead of zeros?
  4 comentarios
Matt J
Matt J el 4 de Dic. de 2017
Editada: Matt J el 4 de Dic. de 2017
How often does sensor failure occur? Is it really often enough to benefit from a sparse representation? That would mean that at least half of your records are invalid.
But in any case, you could, for example, add +1 to all the valid wind speed values so that they are encoded into the interval [1,101]. Then reserve 0 for missing data. Since you clearly don't plan to do linear algebra with this matrix, I don't think this should interfere with anything.
Walter Roberson
Walter Roberson el 4 de Dic. de 2017
Editada: Walter Roberson el 4 de Dic. de 2017
Construct a sparse logical array of locations that are nan. Zero those locations out in the other array and sparse that (assuming that less than about 1/3 of the entries remain as non-zero, to make it worth while to construct the sparse array.)
If more than about 2/3 of your locations are nan, then it might instead make sense to create a logical array of locations which were originally 0 and not nan, and zero out the nan values and sparse the result of that; then the entries in the logical array would say where the "true" zeros are, and the rest of the zeros in the second array would be assumed to be nan.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Sparse Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by