Issue
Hi all looking to weight an array so that the first value , a[0] , is x times the size of the last value, a[-1] . Additionally, i'd like this to be linearly decayed, ie equal parts between each value in the array.
mult = 3
a = [1, 1, 1, 1]
# These conditions should hold true:
# a[0] * 3 = a[-1]
# (a[1] - a[0]) == (a[2] - a[1])
Solution
Use numpy.linspace
:
out = np.linspace(mult*a[-1], a[-1], len(a))
# or
# out = np.linspace(mult, 1, len(a))
Output:
array([3. , 2.33333333, 1.66666667, 1. ])
Answered By - mozway
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.