Azzera filtri
Azzera filtri

Sparse for arrays with lots of NaN.

19 visualizzazioni (ultimi 30 giorni)
Laurent
Laurent il 4 Set 2013
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?

Risposta accettata

Matt J
Matt J il 4 Set 2013
No, but why do you insist on using NaNs instead of zeros?
  4 Commenti
Matt J
Matt J il 4 Dic 2017
Modificato: Matt J il 4 Dic 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 il 4 Dic 2017
Modificato: Walter Roberson il 4 Dic 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Sparse Matrices in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by