Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to find out the maximum cumulative value? Post 302976382 by yuejian on Wednesday 29th of June 2016 01:44:00 AM
Old 06-29-2016
How to find out the maximum cumulative value?

I have a file has thousands of rows and each row has a number and the number can be positive or negative. I want to do the cumulative sum from the first row. How can I find out the maximum cumulative value when I do the sum work row by row. Here is the example:
Code:
4
-3
2
-3
-1
1

In this case, the maximum cumulative value is 3 which is from adding the first 3 rows numbers (4, -3 and 2)
Thank you very much
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to find the maximum # of PIDs

Is there a command in HP Unix which can be used inside a K shell to find out the maximum number of processes (PIDs) a pc can generate? Any help will be greatly appreciated. Steve (8 Replies)
Discussion started by: stevefox
8 Replies

2. UNIX for Dummies Questions & Answers

Find out the maximum growing file in a mount

I need to find the file that is growing in the mount. Say yesterday the utilised space was 95% but today that is 96%. How do i find the file that is growing in size. Have checked the same with du/df options but was not able to find much. Please suggest the best possible option. (3 Replies)
Discussion started by: raman1605
3 Replies

3. Shell Programming and Scripting

TO find the word which occurs maximum number of times

Hi Folks !!!!!!!!!!!!!!!!!!! My Requirement is............. i have a input file: 501,501.chan 502,502.anand 503,503.biji 504,504.raja 505,505.chan 506,506.anand 507,507.chan and my o/p should be chan->3 i.e. the word which occurs maximum number of times in a file should be... (5 Replies)
Discussion started by: aajan
5 Replies

4. UNIX for Dummies Questions & Answers

Please help me to find out maximum value of a field based on grouping of other fields.

Please help me to find out maximum value of a field based on grouping of other fields, as we do in SQL. Like in SQL if we are having below records : Client_Name Associate_Name Date1 Value C1111 A1111 2012-01-17 10 C1111 A1111 ... (1 Reply)
Discussion started by: KamalKumarKalra
1 Replies

5. Homework & Coursework Questions

Find the Maximum value and average of a column

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am trying to complete a script which will allow me to find: a) reads a value from the keyboard. (ask the... (4 Replies)
Discussion started by: dstewie
4 Replies

6. Shell Programming and Scripting

Find the maximum of a value

0.01 0.6 0.39 0.4 0.3 0.3 1 0 0 0 0 1 I would like to print 2 if the maximum of a row is the first column I would like to print 1 if the maximum of a row is the second colum print 0 if it is the third. so in this case, 0.6 is the max of the first row so i would want to print 1... (5 Replies)
Discussion started by: johnkim0806
5 Replies

7. UNIX for Dummies Questions & Answers

Using awk to find and use the maximum value in column of data

Dear Unix Gurus, I have a text file with multiple columns, for example, see sample.txt below 0 1 301 1 4 250 2 6 140 3 2 610 7 1 180I want to find the maximum in, say, column 3, normalise all the values to this maximum value (to 4 decimal places) and spit everything into a new... (2 Replies)
Discussion started by: tintin72
2 Replies

8. Shell Programming and Scripting

Find the maximum value and take value from the neigbouring cells

Let say I have this table A B 0.30 C D 0.60 E F 0.80 G H 0.11 I J 0.10 K L 0.23 M N 0.50 O P 0.01 I need to find the maximum value in each row and output the highest value plus the information two columns back. For example: the output should look like this E F 0.80 M N 0.50 Thanks in... (2 Replies)
Discussion started by: seiksoon
2 Replies

9. Shell Programming and Scripting

Find minimum and maximum values based on column with associative array

Hello, I need to find out the minimum and maximum values based on specific column, and then print out the entire row with the max value. Infile.txt: scf6 290173 290416 . + X_047241 T_00113118-1 scf6 290491 290957 . + X_047241 T_00113118-2 scf6 290898 290957 . + X_047241 T_00113119-3 scf6... (2 Replies)
Discussion started by: yifangt
2 Replies

10. Shell Programming and Scripting

awk to find maximum and minimum from column and store in other column

Need your support for below. Please help to get required output If column 5 is INV then only consider column1 and take out duplicates/identical rows/values from column1 and then put minimum value of column6 in column7 and put maximum value in column 8 and then need to do subtract values of... (7 Replies)
Discussion started by: as7951
7 Replies
Ufunc(3)						User Contributed Perl Documentation						  Ufunc(3)

NAME
PDL::Ufunc - primitive ufunc operations for pdl DESCRIPTION
This module provides some primitive and useful functions defined using PDL::PP based on functionality of what are sometimes called ufuncs (for example NumPY and Mathematica talk about these). It collects all the functions generally used to "reduce" or "accumulate" along a dimension. These all do their job across the first dimension but by using the slicing functions you can do it on any dimension. The PDL::Reduce module provides an alternative interface to many of the functions in this module. SYNOPSIS
use PDL::Ufunc; FUNCTIONS
prodover Signature: (a(n); int+ [o]b()) Project via product to N-1 dimensions This function reduces the dimensionality of a piddle by one by taking the product along the 1st dimension. By using xchg etc. it is possible to use any dimension. $a = prodover($b); $spectrum = prodover $image->xchg(0,1) dprodover Signature: (a(n); double [o]b()) Project via product to N-1 dimensions This function reduces the dimensionality of a piddle by one by taking the product along the 1st dimension. By using xchg etc. it is possible to use any dimension. $a = dprodover($b); $spectrum = dprodover $image->xchg(0,1) Unlike prodover, the calculations are performed in double precision. cumuprodover Signature: (a(n); int+ [o]b(n)) Cumulative product This function calculates the cumulative product along the 1st dimension. By using xchg etc. it is possible to use any dimension. The sum is started so that the first element in the cumulative product is the first element of the parameter. $a = cumuprodover($b); $spectrum = cumuprodover $image->xchg(0,1) dcumuprodover Signature: (a(n); double [o]b(n)) Cumulative product This function calculates the cumulative product along the 1st dimension. By using xchg etc. it is possible to use any dimension. The sum is started so that the first element in the cumulative product is the first element of the parameter. $a = cumuprodover($b); $spectrum = cumuprodover $image->xchg(0,1) Unlike cumuprodover, the calculations are performed in double precision. sumover Signature: (a(n); int+ [o]b()) Project via sum to N-1 dimensions This function reduces the dimensionality of a piddle by one by taking the sum along the 1st dimension. By using xchg etc. it is possible to use any dimension. $a = sumover($b); $spectrum = sumover $image->xchg(0,1) dsumover Signature: (a(n); double [o]b()) Project via sum to N-1 dimensions This function reduces the dimensionality of a piddle by one by taking the sum along the 1st dimension. By using xchg etc. it is possible to use any dimension. $a = dsumover($b); $spectrum = dsumover $image->xchg(0,1) Unlike sumover, the calculations are performed in double precision. cumusumover Signature: (a(n); int+ [o]b(n)) Cumulative sum This function calculates the cumulative sum along the 1st dimension. By using xchg etc. it is possible to use any dimension. The sum is started so that the first element in the cumulative sum is the first element of the parameter. $a = cumusumover($b); $spectrum = cumusumover $image->xchg(0,1) dcumusumover Signature: (a(n); double [o]b(n)) Cumulative sum This function calculates the cumulative sum along the 1st dimension. By using xchg etc. it is possible to use any dimension. The sum is started so that the first element in the cumulative sum is the first element of the parameter. $a = cumusumover($b); $spectrum = cumusumover $image->xchg(0,1) Unlike cumusumover, the calculations are performed in double precision. orover Signature: (a(n); int+ [o]b()) Project via or to N-1 dimensions This function reduces the dimensionality of a piddle by one by taking the or along the 1st dimension. By using xchg etc. it is possible to use any dimension. $a = orover($b); $spectrum = orover $image->xchg(0,1) bandover Signature: (a(n); int+ [o]b()) Project via bitwise and to N-1 dimensions This function reduces the dimensionality of a piddle by one by taking the bitwise and along the 1st dimension. By using xchg etc. it is possible to use any dimension. $a = bandover($b); $spectrum = bandover $image->xchg(0,1) borover Signature: (a(n); int+ [o]b()) Project via bitwise or to N-1 dimensions This function reduces the dimensionality of a piddle by one by taking the bitwise or along the 1st dimension. By using xchg etc. it is possible to use any dimension. $a = borover($b); $spectrum = borover $image->xchg(0,1) zcover Signature: (a(n); int+ [o]b()) Project via == 0 to N-1 dimensions This function reduces the dimensionality of a piddle by one by taking the == 0 along the 1st dimension. By using xchg etc. it is possible to use any dimension. $a = zcover($b); $spectrum = zcover $image->xchg(0,1) andover Signature: (a(n); int+ [o]b()) Project via and to N-1 dimensions This function reduces the dimensionality of a piddle by one by taking the and along the 1st dimension. By using xchg etc. it is possible to use any dimension. $a = andover($b); $spectrum = andover $image->xchg(0,1) intover Signature: (a(n); int+ [o]b()) Project via integral to N-1 dimensions This function reduces the dimensionality of a piddle by one by taking the integral along the 1st dimension. By using xchg etc. it is possible to use any dimension. $a = intover($b); $spectrum = intover $image->xchg(0,1) Notes: For "n > 3", these are all "O(h^4)" (like Simpson's rule), but are integrals between the end points assuming the pdl gives values just at these centres: for such `functions', sumover is correct to O(h), but is the natural (and correct) choice for binned data, of course. average Signature: (a(n); int+ [o]b()) Project via average to N-1 dimensions This function reduces the dimensionality of a piddle by one by taking the average along the 1st dimension. By using xchg etc. it is possible to use any dimension. $a = average($b); $spectrum = average $image->xchg(0,1) daverage Signature: (a(n); double [o]b()) Project via average to N-1 dimensions This function reduces the dimensionality of a piddle by one by taking the average along the 1st dimension. By using xchg etc. it is possible to use any dimension. $a = daverage($b); $spectrum = daverage $image->xchg(0,1) Unlike average, the calculation is performed in double precision. medover Signature: (a(n); [o]b(); [t]tmp(n)) Project via median to N-1 dimensions This function reduces the dimensionality of a piddle by one by taking the median along the 1st dimension. By using xchg etc. it is possible to use any dimension. $a = medover($b); $spectrum = medover $image->xchg(0,1) oddmedover Signature: (a(n); [o]b(); [t]tmp(n)) Project via oddmedian to N-1 dimensions This function reduces the dimensionality of a piddle by one by taking the oddmedian along the 1st dimension. By using xchg etc. it is possible to use any dimension. $a = oddmedover($b); $spectrum = oddmedover $image->xchg(0,1) The median is sometimes not a good choice as if the array has an even number of elements it lies half-way between the two middle values - thus it does not always correspond to a data value. The lower-odd median is just the lower of these two values and so it ALWAYS sits on an actual data value which is useful in some circumstances. pctover Signature: (a(n); p(); [o]b(); [t]tmp(n)) Project via percentile to N-1 dimensions This function reduces the dimensionality of a piddle by one by finding the specified percentile (p) along the 1st dimension. The specified percentile must be between 0.0 and 1.0. When the specified percentile falls between data points, the result is interpolated. By using xchg etc. it is possible to use any dimension. $a = pctover($b, $p); $spectrum = pctover $image->xchg(0,1) $p oddpctover Signature: (a(n); p(); [o]b(); [t]tmp(n)) Project via percentile to N-1 dimensions This function reduces the dimensionality of a piddle by one by finding the specified percentile along the 1st dimension. The specified percentile must be between 0.0 and 1.0. When the specified percentile falls between two values, the nearest data value is the result. By using xchg etc. it is possible to use any dimension. $a = oddpctover($b, $p); $spectrum = oddpctover $image->xchg(0,1) $p pct Return the specified percentile of all elements in a piddle. The specified percentile (p) must be between 0.0 and 1.0. When the specified percentile falls between data points, the result is interpolated. $x = pct($data, $pct); oddpct Return the specified percentile of all elements in a piddle. The specified percentile must be between 0.0 and 1.0. When the specified per- centile falls between two values, the nearest data value is the result. $x = oddpct($data, $pct); avg Return the average of all elements in a piddle $x = avg($data); sum Return the sum of all elements in a piddle $x = sum($data); prod Return the product of all elements in a piddle $x = prod($data); davg Return the average (in double precision) of all elements in a piddle $x = davg($data); dsum Return the sum (in double precision) of all elements in a piddle $x = dsum($data); dprod Return the product (in double precision) of all elements in a piddle $x = dprod($data); zcheck Return the check for zero of all elements in a piddle $x = zcheck($data); and Return the logical and of all elements in a piddle $x = and($data); band Return the bitwise and of all elements in a piddle $x = band($data); or Return the logical or of all elements in a piddle $x = or($data); bor Return the bitwise or of all elements in a piddle $x = bor($data); min Return the minimum of all elements in a piddle $x = min($data); max Return the maximum of all elements in a piddle $x = max($data); median Return the median of all elements in a piddle $x = median($data); oddmedian Return the oddmedian of all elements in a piddle $x = oddmedian($data); any Return true if any element in piddle set Useful in conditional expressions: if (any $a>15) { print "some values are greater than 15 " } all Return true if all elements in piddle set Useful in conditional expressions: if (all $a>15) { print "all values are greater than 15 " } minmax Returns an array with minimum and maximum values of a piddle. ($mn, $mx) = minmax($pdl); This routine does not thread over the dimensions of $pdl; it returns the minimum and maximum values of the whole array. See minmaximum if this is not what is required. The two values are returned as Perl scalars similar to min/max. perldl> $x = pdl [1,-2,3,5,0] perldl> ($min, $max) = minmax($x); perldl> p "$min $max "; -2 5 qsort Signature: (a(n); [o]b(n)) Quicksort a vector into ascending order. print qsort random(10); qsorti Signature: (a(n); int [o]indx(n)) Quicksort a vector and return index of elements in ascending order. $ix = qsorti $a; print $a->index($ix); # Sorted list minimum Signature: (a(n); [o]c()) Project via minimum to N-1 dimensions This function reduces the dimensionality of a piddle by one by taking the minimum along the 1st dimension. By using xchg etc. it is possible to use any dimension. $a = minimum($b); $spectrum = minimum $image->xchg(0,1) minimum_ind Signature: (a(n); int [o] c()) Like minimum but returns the index rather than the value minimum_n_ind Signature: (a(n); int[o]c(m)) Returns the index of "m" minimum elements maximum Signature: (a(n); [o]c()) Project via maximum to N-1 dimensions This function reduces the dimensionality of a piddle by one by taking the maximum along the 1st dimension. By using xchg etc. it is possible to use any dimension. $a = maximum($b); $spectrum = maximum $image->xchg(0,1) maximum_ind Signature: (a(n); int [o] c()) Like maximum but returns the index rather than the value maximum_n_ind Signature: (a(n); int[o]c(m)) Returns the index of "m" maximum elements minmaximum Signature: (a(n); [o]cmin(); [o] cmax(); int [o]cmin_ind(); int [o]cmax_ind()) Find minimum and maximum and their indices for a given piddle; perldl> $a=pdl [[-2,3,4],[1,0,3]] perldl> ($min, $max, $min_ind, $max_ind)=minmaximum($a) perldl> p $min, $max, $min_ind, $max_ind [-2 0] [4 3] [0 1] [2 2] See also minmax, which clumps the piddle together. AUTHOR
Copyright (C) Tuomas J. Lukka 1997 (lukka@husc.harvard.edu). Contributions by Christian Soeller (c.soeller@auckland.ac.nz) and Karl Glaze- brook (kgb@aaoepp.aao.gov.au). All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation under certain conditions. For details, see the file COPYING in the PDL distribution. If this file is separated from the PDL distribution, the copyright notice should be included in the file. perl v5.8.0 2003-01-29 Ufunc(3)
All times are GMT -4. The time now is 02:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy