1 | #! /usr/bin/env python |
---|
2 | |
---|
3 | import numpy |
---|
4 | from ._aubio import __version__ as version |
---|
5 | from ._aubio import float_type |
---|
6 | from ._aubio import * |
---|
7 | from .midiconv import * |
---|
8 | from .slicing import * |
---|
9 | |
---|
10 | class fvec(numpy.ndarray): |
---|
11 | """fvec(input_arg=1024, **kwargs) |
---|
12 | A vector holding float samples. |
---|
13 | |
---|
14 | If `input_arg` is an `int`, a 1-dimensional vector of length `input_arg` |
---|
15 | will be created and filled with zeros. Otherwise, if `input_arg` is an |
---|
16 | `array_like` object, it will be converted to a 1-dimensional vector of |
---|
17 | type :data:`float_type`. |
---|
18 | |
---|
19 | Parameters |
---|
20 | ---------- |
---|
21 | input_arg : `int` or `array_like` |
---|
22 | Can be a positive integer, or any object that can be converted to |
---|
23 | a numpy array with :func:`numpy.array`. |
---|
24 | **kwargs |
---|
25 | Additional keyword arguments passed to :func:`numpy.zeros`, if |
---|
26 | `input_arg` is an integer, or to :func:`numpy.array`. Should not |
---|
27 | include `dtype`, which is already specified as |
---|
28 | :data:`aubio.float_type`. |
---|
29 | |
---|
30 | Returns |
---|
31 | ------- |
---|
32 | numpy.ndarray |
---|
33 | Array of shape `(length,)`. |
---|
34 | |
---|
35 | Examples |
---|
36 | -------- |
---|
37 | >>> aubio.fvec(10) |
---|
38 | array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32) |
---|
39 | >>> aubio.fvec([0,1,2]) |
---|
40 | array([0., 1., 2.], dtype=float32) |
---|
41 | >>> a = np.arange(10); type(a), type(aubio.fvec(a)) |
---|
42 | (<class 'numpy.ndarray'>, <class 'numpy.ndarray'>) |
---|
43 | >>> a.dtype, aubio.fvec(a).dtype |
---|
44 | (dtype('int64'), dtype('float32')) |
---|
45 | |
---|
46 | Notes |
---|
47 | ----- |
---|
48 | |
---|
49 | In the Python world, `fvec` is simply a subclass of |
---|
50 | :class:`numpy.ndarray`. In practice, any 1-dimensional `numpy.ndarray` of |
---|
51 | `dtype` :data:`float_type` may be passed to methods accepting |
---|
52 | `fvec` as parameter. For instance, `sink()` or `pvoc()`. |
---|
53 | |
---|
54 | See Also |
---|
55 | -------- |
---|
56 | cvec : a container holding spectral data |
---|
57 | numpy.ndarray : parent class of :class:`fvec` |
---|
58 | numpy.zeros : create a numpy array filled with zeros |
---|
59 | numpy.array : create a numpy array from an existing object |
---|
60 | """ |
---|
61 | def __new__(cls, input_arg=1024, **kwargs): |
---|
62 | if isinstance(input_arg, int): |
---|
63 | if input_arg == 0: |
---|
64 | raise ValueError("vector length of 1 or more expected") |
---|
65 | return numpy.zeros(input_arg, dtype=float_type, **kwargs) |
---|
66 | else: |
---|
67 | return numpy.array(input_arg, dtype=float_type, **kwargs) |
---|