Quantize¶
-
class
numcodecs.quantize.
Quantize
(digits, dtype, astype=None)[source]¶ Lossy filter to reduce the precision of floating point data.
Parameters: - digits : int
Desired precision (number of decimal digits).
- dtype : dtype
Data type to use for decoded data.
- astype : dtype, optional
Data type to use for encoded data.
Examples
>>> import numcodecs >>> import numpy as np >>> x = np.linspace(0, 1, 10, dtype='f8') >>> x array([0. , 0.11111111, 0.22222222, 0.33333333, 0.44444444, 0.55555556, 0.66666667, 0.77777778, 0.88888889, 1. ]) >>> codec = numcodecs.Quantize(digits=1, dtype='f8') >>> codec.encode(x) array([0. , 0.125 , 0.25 , 0.3125, 0.4375, 0.5625, 0.6875, 0.75 , 0.875 , 1. ]) >>> codec = numcodecs.Quantize(digits=2, dtype='f8') >>> codec.encode(x) array([0. , 0.109375 , 0.21875 , 0.3359375, 0.4453125, 0.5546875, 0.6640625, 0.78125 , 0.890625 , 1. ]) >>> codec = numcodecs.Quantize(digits=3, dtype='f8') >>> codec.encode(x) array([0. , 0.11132812, 0.22265625, 0.33300781, 0.44433594, 0.55566406, 0.66699219, 0.77734375, 0.88867188, 1. ])
-
codec_id
= 'quantize'¶
-
encode
(buf)[source]¶ Encode data in buf.
Parameters: - buf : buffer-like
Data to be encoded. May be any object supporting the new-style buffer protocol.
Returns: - enc : buffer-like
Encoded data. May be any object supporting the new-style buffer protocol.
-
decode
(buf, out=None)[source]¶ Decode data in buf.
Parameters: - buf : buffer-like
Encoded data. May be any object supporting the new-style buffer protocol.
- out : buffer-like, optional
Writeable buffer to store decoded data. N.B. if provided, this buffer must be exactly the right size to store the decoded data.
Returns: - dec : buffer-like
Decoded data. May be any object supporting the new-style buffer protocol.
-
get_config
()[source]¶ Return a dictionary holding configuration parameters for this codec. Must include an ‘id’ field with the codec identifier. All values must be compatible with JSON encoding.
-
classmethod
from_config
(config)¶ Instantiate codec from a configuration object.