Main

Python Functions

Main.PythonFunctions History

Hide minor edits - Show changes to output

Deleted lines 36-37:

!!!!Additional Tutorials
Changed lines 5-6 from:
The following tutorial is an introduction to Python functions such as average, standard deviation, maximum, minimum, and conditional counting.
to:
The following tutorial is an introduction to built-in Python functions such as average, standard deviation, maximum, minimum, and conditional counting.
Added lines 42-75:
!!!! Non-Ideal Gas Function Example

(:html:)
<iframe width="560" height="315" src="https://www.youtube.com/embed/oX-kpj3fAZQ" frameborder="0" allowfullscreen></iframe>
(:htmlend:)

!!!! Source Code

 def P_RK_IG(V, T, do_ideal_gas=False):
    R = 0.0821  # L-atm/K
    Pc = 37.2  # atm
    Tc = 132.5  # K

    a = 0.427 * pow(R,2) * pow(Tc,2.5) / Pc
    b = 0.0866 * R * Tc / Pc

    # Compute in atm
    P_ig = R * T / V
    P_rk = R * T / (V-b) - a/(V*(V+b)*pow(T,0.5))

    # Convert to Pascals
    if do_ideal_gas:
      return P_ig * 101325
    else:
      return P_rk * 101325

 for T in range(490,511,10):
    V = 4.0
    while V < 8:
      print("----- Temperature: " + str(T) + " K")
      print("P_ig: " + str(P_RK_IG(V,T,True)) + " Pa")
      print("P_rk: " + str(P_RK_IG(V,T)) + " Pa")
      V = V + 2.0
 
Changed lines 1-6 from:
(:title MATLAB Statistical Functions:)
(:keywords big data, data analysis, Mathworks, MATLAB, statistics, average, min, max, stdev, university course:)
(:description Introduction to statistical functions in MATLAB, implemented to analyze a data set:)

The following tutorial is an introduction to MATLAB functions such as average, standard deviation, maximum, minimum, and conditional counting.
to:
(:title Python Functions:)
(:keywords big data, data analysis, Python, iPython notebook, spreadsheet, average, min, max, stdev, university course:)
(:description Introduction to statistical functions in Python, implemented to analyze a data set:)

The following tutorial is an introduction to Python functions such as average, standard deviation, maximum, minimum, and conditional counting.
Changed line 8 from:
<iframe width="560" height="315" src="https://www.youtube.com/embed/gHWkS2CyScs" frameborder="0" allowfullscreen></iframe>
to:
<iframe width="560" height="315" src="https://www.youtube.com/embed/ofWU-kNrWMk" frameborder="0" allowfullscreen></iframe>
Changed lines 11-38 from:
!!!!MATLAB Source Code

 % clear session and screen
 clear all; clc
 % create a new column vector with 10 elements
 %
  with random numbers between 0 and 100
 
y = rand(10,1) * 100;
 disp(y)
 % basic statistics
 mean
(y)
 max(y)
 min(y)
 std(y)
 % define a new anonymous function
 avg = @
(x) sum(x)/length(x)
 % check new function
 disp
('Average with avg function: ')
 avg(y)
 disp('Average with mean function: '
)
 mean(y)
 % number of values below 50
 % boolean vector of 0 or 1 values
 disp
(y<50)
 % display result
 disp
('Number of values below 50: ')
 z = y<50;
 disp(sum(z
))
to:
!!!!Python Source Code

 import random
 y = [random.random()*100.0 for i in range(10)]
 print("Print y")
 print(y)

 print("Sorted List")
 for i in range(len(y)):
     print("%.2f" % y[i])

 def avg
(x):
     return sum(x) / len(x)

 print("Avg: " + str(avg(y)))
 print("Max: " + str
(max(y)))
 print("Min: " + str(min(y)))
 z = sum(1 if i<50.0 else 0 for i in y
)
 print("Number Below 50: " + str(z))

 # another method with NumPy
 import numpy as np
 print
(np.mean(y))
 print
(np.average(y))
 print(np.std(y))
 print(np.median(y
))
Changed line 40 from:
Data statistics can also be completed with a spreadsheet program  like [[Main/ExcelFunctions|Microsoft Excel]] and [[Main/PythonFunctions|Python]] where the data sets are arrays or matrices instead of tables in a spreadsheet. Click on the appropriate link for additional information and source code.
to:
Data statistics can also be completed with a spreadsheet program  like [[Main/ExcelFunctions|Microsoft Excel]] and [[Main/MatlabFunctions|MATLAB]] where the data sets are arrays or matrices instead of tables in a spreadsheet. Click on the appropriate link for additional information and source code.
Added lines 13-37:
 % clear session and screen
 clear all; clc
 % create a new column vector with 10 elements
 %  with random numbers between 0 and 100
 y = rand(10,1) * 100;
 disp(y)
 % basic statistics
 mean(y)
 max(y)
 min(y)
 std(y)
 % define a new anonymous function
 avg = @(x) sum(x)/length(x)
 % check new function
 disp('Average with avg function: ')
 avg(y)
 disp('Average with mean function: ')
 mean(y)
 % number of values below 50
 % boolean vector of 0 or 1 values
 disp(y<50)
 % display result
 disp('Number of values below 50: ')
 z = y<50;
 disp(sum(z))
Changed lines 1-6 from:
(:title Python Functions:)
(:keywords big data, data analysis, Python, iPython notebook, spreadsheet, average, min, max, stdev, university course:)
(:description Introduction to statistical functions in Python, implemented to analyze a data set:)

The following tutorial is an introduction to Python functions such as average, standard deviation, maximum, minimum, and conditional counting.
to:
(:title MATLAB Statistical Functions:)
(:keywords big data, data analysis, Mathworks, MATLAB, statistics, average, min, max, stdev, university course:)
(:description Introduction to statistical functions in MATLAB, implemented to analyze a data set:)

The following tutorial is an introduction to MATLAB functions such as average, standard deviation, maximum, minimum, and conditional counting.
Changed line 8 from:
<iframe width="560" height="315" src="https://www.youtube.com/embed/ofWU-kNrWMk" frameborder="0" allowfullscreen></iframe>
to:
<iframe width="560" height="315" src="https://www.youtube.com/embed/gHWkS2CyScs" frameborder="0" allowfullscreen></iframe>
Changed lines 11-37 from:
!!!!Python Source Code

 import random
 y = [random.random()*100.0 for i in range(10)]
 print("Print y")
 print(y)

 print("Sorted List")
 for i in range(len(y)):
    print("%.2f" % y[i])

 def avg(x):
    return sum(x) / len(x)

 print("Avg: " + str(avg(y)))
 print("Max: " + str(max(y)))
 print("Min: " + str(min(y)))
 icount = sum(1 if i<50.0 else 0 for i in y)
 print("Numbers Below 50: " + str(icount))

 # another method with NumPy
 import numpy as np
 print(np.mean(y))
 print(np.average(y))
 print(np.std(y))
 print(np.median(y))

to:
!!!!MATLAB Source Code

Changed line 16 from:
Data statistics can also be completed with a spreadsheet program  like [[Main/ExcelFunctions|Microsoft Excel]] and [[Main/MatlabFunctions|MATLAB]] where the data sets are arrays or matrices instead of tables in a spreadsheet. Click on the appropriate link for additional information and source code.
to:
Data statistics can also be completed with a spreadsheet program  like [[Main/ExcelFunctions|Microsoft Excel]] and [[Main/PythonFunctions|Python]] where the data sets are arrays or matrices instead of tables in a spreadsheet. Click on the appropriate link for additional information and source code.
Changed lines 28-29 from:
 print("Number Below 50: " + str(sum(1 if i<50.0 else 0 for i in y)))
to:
 icount = sum(1 if i<50.0 else 0 for i in y)
 print("Numbers Below 50: " + str(icount
))
Added lines 10-37:

!!!!Python Source Code

 import random
 y = [random.random()*100.0 for i in range(10)]
 print("Print y")
 print(y)

 print("Sorted List")
 for i in range(len(y)):
    print("%.2f" % y[i])

 def avg(x):
    return sum(x) / len(x)

 print("Avg: " + str(avg(y)))
 print("Max: " + str(max(y)))
 print("Min: " + str(min(y)))
 print("Number Below 50: " + str(sum(1 if i<50.0 else 0 for i in y)))

 # another method with NumPy
 import numpy as np
 print(np.mean(y))
 print(np.average(y))
 print(np.std(y))
 print(np.median(y))

!!!!Additional Tutorials
Changed line 11 from:
Data statistics can also be completed with a spreadsheet program  like [[Main/ExcelFunctions|Microsoft Excel]] and [[Main/PythonFunctions|Python]] where the data sets are arrays or matrices instead of tables in a spreadsheet. Click on the appropriate link for additional information and source code.
to:
Data statistics can also be completed with a spreadsheet program  like [[Main/ExcelFunctions|Microsoft Excel]] and [[Main/MatlabFunctions|MATLAB]] where the data sets are arrays or matrices instead of tables in a spreadsheet. Click on the appropriate link for additional information and source code.
Added lines 1-30:
(:title Python Functions:)
(:keywords big data, data analysis, Python, iPython notebook, spreadsheet, average, min, max, stdev, university course:)
(:description Introduction to statistical functions in Python, implemented to analyze a data set:)

The following tutorial is an introduction to Python functions such as average, standard deviation, maximum, minimum, and conditional counting.

(:html:)
<iframe width="560" height="315" src="https://www.youtube.com/embed/ofWU-kNrWMk" frameborder="0" allowfullscreen></iframe>
(:htmlend:)

Data statistics can also be completed with a spreadsheet program  like [[Main/ExcelFunctions|Microsoft Excel]] and [[Main/PythonFunctions|Python]] where the data sets are arrays or matrices instead of tables in a spreadsheet. Click on the appropriate link for additional information and source code.

----

(:html:)
 <div id="disqus_thread"></div>
    <script type="text/javascript">
        /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
        var disqus_shortname = 'apmonitor'; // required: replace example with your forum shortname

        /* * * DON'T EDIT BELOW THIS LINE * * */
        (function() {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
        })();
    </script>
    <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
(:htmlend:)