python,numpy,matplotlib,median,scatter

I would use np.digitize to do the bin sorting for you. This way you can easily apply any function and set the range you are interested in. import numpy as np import pylab as plt N = 2000 total_bins = 10 # Sample data X = np.random.random(size=N)*10 Y = X**2...

I am posting you the complete solution according to your requirement as far as possible, almost complete you can comment if something went wrong with my code. #include <stdio.h> #include <stdlib.h> #define n 3 int arr[n][n],arr_col[n][n]; int count_row=0,median=0,count_col=0; int min,i,j,tmp,y,k,w,z=0,q=0; char op,op1; void row_median(); void col_median(); void print(); void...

We ended up updating the medians every page request, rather than in bulk with a cron job or something. We have a Node API that uses Mongo's aggregation framework to do the match/sort the user's results. The array of results then pass to a median function within Node. The results...

python,python-3.x,median,python-3.4

You should put a colon (:) on the first line (def) as well. This works for the online python environment: def input(a, b, c) : if a <= b <= c or c <= b <= a : return b elif b <= a <= c or c <= a...

Just to spell it out for you, this is what you need to change: double[] median = new double[inData.size()]; for (int i=0; i < inData.size(); i++) { String[] word = inData.get(i).split(", "); double m = Double.parseDouble(word[3].substring (0,5)); median[i] = m; } Arrays.sort(median); And then every reference to m after this...

One approach is to untangle or unlist the data frame before calculating the median: > df <- data.frame( + Prop1 = c('A','B','C'), Prop2 = c('D','E','F'), Prop3 = c('G','H','I'), + Value1 = c(1:3), Value2 = c(4:6), Value3 = c(7:9)) > df Prop1 Prop2 Prop3 Value1 Value2 Value3 1 A D G...

python,arrays,numpy,nan,median

import numpy as np from numpy import NaN x = np.array([NaN,NaN,0.1,0.002,0.14,NaN,NaN,NaN]) def getMedian(arr): med = np.median(arr) if np.isnan(med): return np.nanmax(arr) else: return med print getMedian(x) ...

How about median(unlist(x), na.rm = TRUE) #[1] 7.052172 Edit after comment y <- unlist(x) q <- quantile(y, na.rm = TRUE) median(y[y > q[4]], na.rm = TRUE) #[1] 22.96025 Is that what you mean?...

algorithm,statistics,median,standard-deviation,outliers

Based on the description you have provided, the problem can be split into 2: Finding and excluding Statistical Outliers from the data set Sorting the resulting values in descending (or just in any) order The general solution to the first problem and example using Microsoft Excel is described at :...

image,matlab,image-processing,filter,median

The basic premise behind median filtering is to analyze pixel neighbourhoods in your image, sort their intensities, then choose the middle intensity as the result. One suggestion I can make is to use im2col to transform each pixel neighbourhood into a single column vector and take all of these column...

c++,sorting,unhandled-exception,median

If list[p] == list[r] then pivot is not assigned any value from the array and stays with its default value of zero. And if all items of the array are greater than zero, or all are less than zero, then one of the while loops runs p or r out...

I believe the first test is true if lowest bit is zero, i.e. sum is even number. The second test is true if size is odd number (i.e. LSB is set).

javascript,jquery,html,math,median

To do this with a single input: split the input's value on commas. This will return an array of numbers. Use a for loop to iterate through the array, keeping track of the running total. The average will be the grand total divided by the array's length. To calculate median:...

linux,bash,windows-mobile,median

You could use awk to realize this. For example when you have your data in a file named in.txt: awk '{c[NR]=$1; asort(c); if (NR%2) {print c[(NR+1)/2]} else {print (c[(NR/2)]+c[(NR/2)+1]) / 2.0}}' < in.txt results in the output 1 1.5 2 18.5 35 ...

excel,vba,excel-vba,excel-2010,median

Edit: Fixed some syntax. You have to pass all the highlighted cells into one master range then run the function on the master range. Sub Macro1() Dim amarelosMediana As Range Dim tempRng As Range Dim mediana As Double Set tempRng = Nothing For Each amarelosMediana In Range([a1], Cells(Rows.Count, "A").End(xlUp)) If...

arrays,algorithm,sorting,median

You can solve this problem by applying X recursively. Consider the following sub-routine Y: Given an array of length n as input, we first apply the method X to find the median m of the input numbers, this takes time O(n). We then scan the input array to rearrange the...

sql,sql-server-2008,date,median

If you mean the set of start dates and end dates, then put them in one column: WITH t AS ( SELECT invoice_no, invoice_start_date, invoice_end_date, check_date, status_code, FROM INVOICE_HEADER INNER JOIN INVOICE_HEADER_CUSTOM ON INVOICE_HEADER.invoice_id = INVOICE_HEADER_CUSTOM.invoice_id WHERE status_code <> 'REJECTED' AND Check_Date BETWEEN CONVERT(DATETIME, '2014-12-01 00:00:00', 102) AND CONVERT(DATETIME, '2014-12-31...

c++,algorithm,tree,binary-search-tree,median

Make index a static local variable in the function findMedian. This is not recommended but one solution when it is insisted on having one const recursive function.

Your problem is that you only initialize the min and max variables once, outside the while loop. Your code will work if you initialize inside the loop. This code works. Note that I changed the variable names to not be Python built-ins. You shouldn't use names that "shadow" built-ins; for...

number_images = 60; offset = 5; for n=offset+1:1:number_images-offset rolling_interval_IM = squeeze(IM(n-offset:1:n+offset,:,:)); end You didn't say whether you wanted to store each rolling interval so this will just overwrite the previous. It's a bit unusual I think to have the time dimension as your first dimension. That is normally the last...

sql,sql-server-2008,date,median

You were close, only missed a PARTITION BY clause in your count statement. WITH tmp AS ( SELECT invoice_no, dates, cast(count(*) OVER (PARTITION BY invoice_no) as float) AS total, row_number() OVER (PARTITION BY invoice_no ORDER BY dates) AS rn FROM INVOICE_HEADER ) SELECT * FROM tmp WHERE (total / 2.0...

From the information that you have provided so far, I believe it is probably a problem of integer division. In the case when there are an even number of elements in the list, you have to take the average. In python3.4, / does float division but in python2, it does...

Another option is library(dplyr) df %>% mutate_each(funs(median=.-median(., na.rm=TRUE)), -ID) ...

algorithm,tree,binary-search-tree,median

As you mentioned, it is fairly easy to first find the number of nodes, doing any traversal: findNumNodes(node): if node == null: return 0 return findNumNodes(node.left) + findNumNodes(node.right) + 1 Then, with an inorder traversal that aborts when the node number is n/2: index=0 //id is a global variable /...

It has to do with the mad function automatically setting the scaling constant as 1.482. If you do mad(vec, constant=1) You get the same output as your other methods...

matlab,random,statistics,median

Matlab function rand generates (pseudo)-random numbers uniformly distributed on the interval [0,1]. The median of this distribution is 0.5. You can make the median to be m by adding m-0.5 to each number. The function function array = generateNumbers(m, n, medianValue) array = rand(m,n)-0.5 + medianValue; end returns a random...

python,python-3.x,dictionary,mean,median

I don't know how to manipulate the values to find the names of all the students whose grades are above the mean for the class. (the mean being the sum of the values divided by the number of values). You can use a list comprehension to create a sublist...

excel,vba,excel-vba,multiple-columns,median

All you need is to set M9 =MEDIAN(A2:A8) and have the A2:A8 set to the range you want. Then just copy and paste that over to the other columns M9:V9. Excel will auto-change the columns to B,C,D, etc, and will fill in the info you want. Edit for VBA: Here...

c++,stl,functor,median,stl-algorithm

You may use a functor like: class comp_with_indirection { public: explicit comp_with_indirection(const std::vector<float>& floats) : floats(floats) {} bool operator() (int lhs, int rhs) const { return floats[lhs] < floats[rhs]; } private: const std::vector<float>& floats; }; And then you may use it like: int find_median(const std::vector<float>& v_f, std::vector<int> &v_i) { assert(!v_i.empty());...

algorithm,math,geometry,median

You can use the approach shown in the question you linkes: Calculate the average as the angle of accumulated unit vectors of your angles. In my opinion, this approach is not very suited to large sets of vectors. There's another approach that works with weighted interpolations. It doesn't require any...

java,complexity-theory,quicksort,median

You are calling exchange too much with indices that you have already read. You can save a lot of reads by replacing those calls with "manual" calls to setItem. Consider for example the following lines: if (!(x.equals(rItem))) { super.exchange(records, median, r); } If you inspect your code a bit, you'll...

python,statistics,median,percentile,wolframalpha

You have 7 numbers which you are attempting to split into quartiles. Because 7 is not divisible by 4 there are a couple of different ways to do this as mentioned here. Your way is the first given by that link, wolfram alpha seems to be using the third. Numpy...

You haven't correctly introduced the type-parameter T, as Comparable is generic, too. It should rather be: private static <T extends Comparable<? super T>> T median(T a, T b, T c) Furthermore, you can just sort the medianHelper list, since its elements will be Comparable. So your method can be significantly...

Here are two implementations for your median() and mode() methods: public void computeMedian() { Arrays.sort(list); if ( (list.size & 1) == 0 ) { // even: take the average of the two middle elements median = (list[(size/2)-1] + list[(size/2)]) / 2; } else { // odd: take the middle element...

c++,algorithm,c++11,median,minimize

Given an array x1, x2, …, xn of integers, the real number z that minimizes ∑i∈{1,2,…,n} (z - xi)2 is the mean z* = (1/n) ∑i∈{1,2,…,n} xi. You want to call std::min_element with a comparator that treats xi as less than xj if and only if |n xi - n...

image,image-processing,type-conversion,median,idl-programming-language

I would use ImageMagick. It is free and available from the command line in most Unixes/Linuxes and has C/C++, Perl, PHP bindings too. It is available here. If you have a number of JPEG files in your current directory, you can get the median with a simple command like this...

Your while loops do not alter the variable element_count, and so the condition of the loop never change, looping forever. element_count always remains the value of the size of the original array. A quick fix is below: ... while element_count != 1 do array.shift array.pop element_count = array.length end ......

As a complement to @Miki's answer I remind you that a median filter is one that given N samples (in this case taken from the 3x3 square around central pixels) sorts their value and takes the one in the middle. So given (1, 7, 2, 2, 1, 9, 22, 4,...

excel,excel-formula,worksheet-function,median,array-formulas

Maybe: =MEDIAN(IF(A:A="A",B:B)) entered CSE....