source: python/lib/aubio/__init__.py @ e2010b3

feature/crepe_org
Last change on this file since e2010b3 was 450c57e, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[py] add blank line after imports in init.py

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[229d050]1#! /usr/bin/env python
[7cfad8e]2# -*- coding: utf8 -*-
3
4"""
5aubio
6=====
7
8Provides a number of classes and functions for music and audio signal
9analysis.
10
11How to use the documentation
12----------------------------
13
14Documentation of the python module is available as docstrings provided
15within the code, and a reference guide available online from `the
16aubio homepage <https://aubio.org/documentation>`_.
17
18The docstrings examples are written assuming `aubio` and `numpy` have been
19imported with:
20
21>>> import aubio
22>>> import numpy as np
23"""
[229d050]24
[ccca7cb]25import numpy
[883b499]26from ._aubio import __version__ as version
[b96a7b8]27from ._aubio import float_type
[883b499]28from ._aubio import *
[4de5f35]29from .midiconv import *
30from .slicing import *
[ccca7cb]31
[450c57e]32
[ccca7cb]33class fvec(numpy.ndarray):
[7a54b37]34    """fvec(input_arg=1024)
[78c1d32]35    A vector holding float samples.
[8bffcff]36
[78c1d32]37    If `input_arg` is an `int`, a 1-dimensional vector of length `input_arg`
38    will be created and filled with zeros. Otherwise, if `input_arg` is an
39    `array_like` object, it will be converted to a 1-dimensional vector of
40    type :data:`float_type`.
41
42    Parameters
43    ----------
44    input_arg : `int` or `array_like`
45        Can be a positive integer, or any object that can be converted to
46        a numpy array with :func:`numpy.array`.
47
48    Examples
49    --------
50    >>> aubio.fvec(10)
51    array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32)
52    >>> aubio.fvec([0,1,2])
53    array([0., 1., 2.], dtype=float32)
54    >>> a = np.arange(10); type(a), type(aubio.fvec(a))
55    (<class 'numpy.ndarray'>, <class 'numpy.ndarray'>)
56    >>> a.dtype, aubio.fvec(a).dtype
57    (dtype('int64'), dtype('float32'))
58
59    Notes
60    -----
61
62    In the Python world, `fvec` is simply a subclass of
63    :class:`numpy.ndarray`. In practice, any 1-dimensional `numpy.ndarray` of
64    `dtype` :data:`float_type` may be passed to methods accepting
65    `fvec` as parameter. For instance, `sink()` or `pvoc()`.
66
67    See Also
68    --------
69    cvec : a container holding spectral data
70    numpy.ndarray : parent class of :class:`fvec`
71    numpy.zeros : create a numpy array filled with zeros
72    numpy.array : create a numpy array from an existing object
73    """
[7a54b37]74    def __new__(cls, input_arg=1024):
[143682b]75        if isinstance(input_arg, int):
[b96a7b8]76            if input_arg == 0:
77                raise ValueError("vector length of 1 or more expected")
[7a54b37]78            return numpy.zeros(input_arg, dtype=float_type, order='C')
[143682b]79        else:
[7a54b37]80            np_input = numpy.array(input_arg, dtype=float_type, order='C')
81            if len(np_input.shape) != 1:
82                raise ValueError("input_arg should have shape (n,)")
83            if np_input.shape[0] == 0:
84                raise ValueError("vector length of 1 or more expected")
85            return np_input
Note: See TracBrowser for help on using the repository browser.