C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

## How to get elements larger than x in a given range? Tag : arrays , By : Edo Date : November 24 2020, 01:01 AM

fixed the issue. Will look into that further Code. I'm trying to avoid matrix multiplication, so this may look a bit odd:
``````A = [1:5; 2:6; 3:7; 4:8; 5:9];

[r,c] = meshgrid(2:4,3:5);
n     = sub2ind(size(A), r(:), c(:));

indices = sort(n(A(n) > 5)); %'skip sorting if not needed'
values  = A(indices);
``````
``````A = [1:5; 2:6; 3:7; 4:8; 5:9];

%'For column-first, 1-based-index array memory   '
%'layout, as in MATLAB/FORTRAN, the linear index '
%'formula is:                                    '
%'L = R + (C-1)*NR                               '
n = bsxfun(@plus, (2:4), (transpose(3:5) - 1)*size(A,1));

indices = n(A(n) > 5);
values  = A(indices);
``````

Share :

## Ruby math: take a number from a larger number range and calculate where it falls on a smaller range

Tag : ruby , By : tommy
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
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 }
end
``````

## Find the element in an array, in which left elements are smaller and right elements are larger?

Tag : arrays , By : mhedberg
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()

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

Tag : python , By : KT.
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

Tag : excel , By : 小和尚
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
``````