Created
April 5, 2019 13:35
-
-
Save daguiam/d10dbd6011208c35d083dd46869ff929 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def convert_array_to_levels(array, levels, limits=[-np.pi,np.pi], output_limits=None, verbose=False): | |
"""Dgitizes the given array to within the number of levels provided | |
Parameters | |
---------- | |
array : input array of values | |
levels : number of levels to consider | |
limits : the input data limits to consider for the interval calculation | |
output_limits : if given, multiplies the digitized input to the output range | |
Returns | |
------- | |
a : digitized output | |
""" | |
min_limit = np.min(limits) | |
array_range = np.max(limits)-min_limit | |
interval = array_range/levels | |
ranges = np.arange(1,levels)*interval+min_limit | |
if verbose: | |
print("ranges:", ranges) | |
a = np.digitize(array, ranges) | |
if output_limits is not None: | |
min_limit = np.min(output_limits) | |
array_range = np.max(output_limits)-min_limit | |
interval = array_range/levels | |
return a*interval+min_limit | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment