Filter löschen
Filter löschen

Sparse for arrays with lots of NaN.

19 Ansichten (letzte 30 Tage)
Laurent
Laurent am 4 Sep. 2013
Bearbeitet: Walter Roberson am 4 Dez. 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?

Akzeptierte Antwort

Matt J
Matt J am 4 Sep. 2013
No, but why do you insist on using NaNs instead of zeros?
  4 Kommentare
Matt J
Matt J am 4 Dez. 2017
Bearbeitet: Matt J am 4 Dez. 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 am 4 Dez. 2017
Bearbeitet: Walter Roberson am 4 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Sparse Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by