MCPcopy Index your code
hub / github.com/ipython/ipython / _validate_and_normalize_with_numpy

Method _validate_and_normalize_with_numpy

IPython/lib/display.py:170–189  ·  view source on GitHub ↗
(data, normalize)

Source from the content-addressed store, hash-verified

168
169 @staticmethod
170 def _validate_and_normalize_with_numpy(data, normalize) -> Tuple[bytes, int]:
171 import numpy as np
172
173 data = np.array(data, dtype=float)
174 if len(data.shape) == 1:
175 nchan = 1
176 elif len(data.shape) == 2:
177 # In wave files,channels are interleaved. E.g.,
178 # "L1R1L2R2..." for stereo. See
179 # http://msdn.microsoft.com/en-us/library/windows/hardware/dn653308(v=vs.85).aspx
180 # for channel ordering
181 nchan = data.shape[0]
182 data = data.T.ravel()
183 else:
184 raise ValueError('Array audio input must be a 1D or 2D array')
185
186 max_abs_value = np.max(np.abs(data))
187 normalization_factor = Audio._get_normalization_factor(max_abs_value, normalize)
188 scaled = data / normalization_factor * 32767
189 return scaled.astype("<h").tobytes(), nchan
190
191 @staticmethod
192 def _validate_and_normalize_without_numpy(data, normalize):

Callers 1

_make_wavMethod · 0.80

Calls 1

Tested by

no test coverage detected