-
Notifications
You must be signed in to change notification settings - Fork 52
/
_thermometer.py
42 lines (33 loc) · 1.18 KB
/
_thermometer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
# _thermometer.py
# This module provides the thermometer function.
# Copyright 2013 Giuseppe Venturini
# This file is part of python-deltasigma.
#
# python-deltasigma is a 1:1 Python replacement of Richard Schreier's
# MATLAB delta sigma toolbox (aka "delsigma"), upon which it is heavily based.
# The delta sigma toolbox is (c) 2009, Richard Schreier.
#
# python-deltasigma is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# LICENSE file for the licensing terms.
"""This module provides the thermometer() function.
"""
import numpy as np
def thermometer(x, m):
"""Convert x to thermometer (aka unary) code
**Parameters:**
x : 1-D ndarray
The array of positive ints, each of which will be converted.
m : int
total length of the thermometer array.
**Returns:**
t : ndarray
``t`` is an m by ``len(x)`` matrix wherein the first
``x(i)`` components of column ``i`` are one.
"""
t = np.zeros((m, len(x)))
for i in range(len(x)):
t[:x[i], i] = np.ones((x[i], ))
return t