Ruby math: take a number from a larger number range and calculate where it falls on a smaller range
Date : March 29 2020, 07:55 AM
This might help you If you want the value range to be linearly divided into equal sized subranges, this should do the trick for you: min = scores.values.min
max = scores.values.max
nsub = adjectives.size
tresholds = (1..nsub).map do n
min + (max  min) * (n / nsub.to_f)
end
scores.each_pair do student, score
adj_index = tresholds.index {t t >= score }
puts "#{student} score was in the #{adjectives[adj_idx]}."
end

Find the element in an array, in which left elements are smaller and right elements are larger?
Date : March 29 2020, 07:55 AM
will help you 1) scan the array from left to right, remembering the largest value so far; 2) scan the array from right to left, remembering the smallest value so far. 3 6 4 5 9 8 7
3 6 6 6 9 9 9
3 4 4 5 7 7 7
3 2 4 6 9 8 7
3 3 4 6 9 9 9
2 2 4 6 7 7 7
^ ^

Setting matplotlib colorbar range (larger range than the values plotted)
Tag : python , By : Alex Sadzawka
Date : March 29 2020, 07:55 AM
it helps some times I finally managed to solve it. Instead of vmin and vmax, I must pass a keyword to control the levels to draw, like this: import matplotlib.pyplot as plt
import numpy as np
rd = np.random.rand(40,100)
surface = 18 * rd # maximum value will be 18
fig = plt.figure()
ax = fig.add_subplot(111)
cores = ax.contourf(surface[:], levels=range(41))
cbar = plt.colorbar(cores)
plt.show()

Identifying an assortment of lists whose elements make up the exact elements in a larger list
Date : March 29 2020, 07:55 AM
To fix the issue you can do I think that what you want to find is the set of the partitions of a multiset. To do so you can use sympy as follows: from sympy.utilities.iterables import multiset_partitions
res=[p for p in multiset_partitions(["a","b","c","c","d"])]
[[['a', 'b', 'c', 'c', 'd']],
[['a', 'b', 'c', 'c'], ['d']],
[['a', 'b', 'c', 'd'], ['c']],
[['a', 'b', 'c'], ['c', 'd']],
[['a', 'b', 'c'], ['c'], ['d']],
[['a', 'b', 'd'], ['c', 'c']],
[['a', 'b', 'd'], ['c'], ['c']],
[['a', 'b'], ['c', 'c', 'd']],
[['a', 'b'], ['c', 'c'], ['d']],
[['a', 'b'], ['c', 'd'], ['c']],
[['a', 'b'], ['c'], ['c'], ['d']],
[['a', 'c', 'c', 'd'], ['b']],
[['a', 'c', 'c'], ['b', 'd']],
[['a', 'c', 'c'], ['b'], ['d']],
[['a', 'c', 'd'], ['b', 'c']],
[['a', 'c', 'd'], ['b'], ['c']],
[['a', 'c'], ['b', 'c', 'd']],
[['a', 'c'], ['b', 'c'], ['d']],
[['a', 'c'], ['b', 'd'], ['c']],
[['a', 'c'], ['b'], ['c', 'd']],
[['a', 'c'], ['b'], ['c'], ['d']],
[['a', 'd'], ['b', 'c', 'c']],
[['a', 'd'], ['b', 'c'], ['c']],
[['a', 'd'], ['b'], ['c', 'c']],
[['a', 'd'], ['b'], ['c'], ['c']],
[['a'], ['b', 'c', 'c', 'd']],
[['a'], ['b', 'c', 'c'], ['d']],
[['a'], ['b', 'c', 'd'], ['c']],
[['a'], ['b', 'c'], ['c', 'd']],
[['a'], ['b', 'c'], ['c'], ['d']],
[['a'], ['b', 'd'], ['c', 'c']],
[['a'], ['b', 'd'], ['c'], ['c']],
[['a'], ['b'], ['c', 'c', 'd']],
[['a'], ['b'], ['c', 'c'], ['d']],
[['a'], ['b'], ['c', 'd'], ['c']],
[['a'], ['b'], ['c'], ['c'], ['d']]]

How do I find the largest contiguous n length range within a larger range
Date : March 29 2020, 07:55 AM
I hope this helps . I am trying to find the cell references for the largest n length contiguous subset of values in my range. , Use this: Function MaxN(n&, r As Range)
Dim i&, j&, m#, t#, v, str
v = r.Value2
For i = 1 To UBound(v)
If UBound(v)  i + 1 >= n Then
t = 0
For j = i To i + n  1
t = t + v(j, 1)
Next
If t > m Then
m = t
str = i
End If
Else
Exit For
End If
Next
MaxN = Range(Cells(str, r.Column), Cells(str + n, r.Column)).Address
End Function

