Browse Source

startup: define function `numpy_array_from_file`

Fabian Peter Hammerle 3 years ago
parent
commit
243a1f9cfc
1 changed files with 8 additions and 0 deletions
  1. 8 0
      profile_default/startup/init.py

+ 8 - 0
profile_default/startup/init.py

@@ -7,6 +7,14 @@ import scipy.io.wavfile
 from matplotlib import pyplot  # pylint: disable=unused-import; frequently used in shell
 
 
+def numpy_array_from_file(
+    path: typing.Union[str, pathlib.Path], dtype
+) -> numpy.ndarray:
+    if isinstance(path, str):
+        path = pathlib.Path(path)
+    return numpy.frombuffer(path.read_bytes(), dtype=dtype)
+
+
 def split_sequence_by_delimiter(
     sequence: typing.Sequence, delimiter: typing.Any, delimiter_min_length: int = 1
 ) -> typing.Iterator[typing.Sequence]: