<jupyter_start><jupyter_text>The Python world of science and dataThe [Jupyter notebook](http://nbviewer.jupyter.org/github/barbagroup/jupyter-tutorial/blob/master/1--The%20Notebook.ipynb) is a nice way to write and share some content online, but you'll get superpowers from Python libraries for science and data!We already used code cells to do simple calculations via the arithmetic operators in Python:```python    +   -   *   /   **   %   //```In addition to arithmetics, you can do comparisons with operators that return Boolean values (`True` or `False`). These are:```python    ==   !=      =```On top of those, you have assignment operators, bitwise operators, logical operators, membership operators, and identity operators. You can find online several "cheat sheets" for Python operators. For example: ["Operators and expressions"](http://pymbook.readthedocs.io/en/latest/operatorsexpressions.html) in the online book _"Python for You and Me."_Go ahead and experiment with various Python operators until you're satisfied. You can open a new, empty notebook and experiment in code cells, taking notes of the things that you find interesting in markdown cells. Or, if you have _this_ notebook open in the Jupyter Notebook App, you can add a new cell by clicking the plus button: , and work right here. Remember to type `[shift] + [enter]` to exectue any cell.Next, let's learn about the Python world of science and data.  Two libraries that made Python useful for science: NumPy and MatplotlibPython is a general-purpose language: you can use it to create websites, to write programs that crawl the web, to support you in scientific research or data analysis, etc. Because it can be used in so many fields, the core language is supported by many libraries (not everyone needs to have every functionality). In science, two libraries made Python really useful: [**NumPy**](http://www.numpy.org) and [**Matplotlib**](http://matplotlib.org).**NumPy** gives you access to numerical mathematics on arrays (like vectors and matrices). **Matplotlib** gives you a catalog of plotting functions for visualizing data.<jupyter_code>import numpy<jupyter_output><empty_output><jupyter_text>The command `import` followed by the name of a library will extend your Python session with all of the functions in that library. After executing the code cell above, we have all of **NumPy** available to us. If you have this notebook open in the Jupyter Notebook App, make sure to execute the cell above by clicking on it and typing ``[shift] + [enter]``.Now, to use one of **NumPy**'s functions, we prepend `numpy.` (with the dot) to the function name. For example:<jupyter_code>numpy.linspace(0, 5, 10)<jupyter_output><empty_output><jupyter_text>The **NumPy** function [`linspace()`](http://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html)  creates an array with equally spaced numbers between a start and end. It's a very useful function! In the code cell above, we create an array of 10 numbers from 0 to 5. Go ahead and try it with different argument values.To be able to do something with this array later, we normally want to give it a name. Like,<jupyter_code>xarray = numpy.linspace(0, 5, 10)<jupyter_output><empty_output><jupyter_text>Now, we can use **NumPy** to do computations with the array. Like take its square:<jupyter_code>xarray ** 2<jupyter_output><empty_output><jupyter_text>In **NumPy**, the square of an array of numbers takes the square of each element. You will likely want to give your result a name, too. So let's do this again, and also take the cube, and the square root of the array at the same time.<jupyter_code>yarray = xarray ** 2
zarray = xarray ** 3
warray = numpy.sqrt(xarray)<jupyter_output><empty_output><jupyter_text>You notice that **NumPy** knows how to take the power of an array, and it has a built-in function for the square-root. Now, you may want to draw a plot of these results with the original array on the x-axis. For that we need the module `pyplot` from **Matplotlib**.<jupyter_code>from matplotlib import pyplot
%matplotlib notebook<jupyter_output><empty_output><jupyter_text>The command `%matplotlib notebook` is there to get our plots inside the notebook (instead of a pop-up window, which is the default behavior of `pyplot`). Let's try a line plot now! We use the `pyplot.plot()` function, specifying the line color (`'k'` for black) and line style (`'-'`, `'--'` and `':'` for continuous, dashed and dotted line), and giving each line a label. Note that the values for `color`, `linestyle` and `label` are given in quotes.<jupyter_code>pyplot.plot(xarray,yarray,color='k',linestyle='-', label='square')
pyplot.plot(xarray,zarray,color='k',linestyle='--', label='cube')
pyplot.plot(xarray,warray,color='k',linestyle=':', label='square root')
pyplot.legend(loc='best')
pyplot.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0944558521560575, 'fraction_numerical': 0.003696098562628337, 'mean_word_length': 5.277061855670103, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '154860', 'license': 'MIT', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1356, 'n_words': 631, 'path': 'week1/jupyter-tutorial/2--The Python world of science and data.ipynb', 'repo_name': 'leoliu0/FINS5517', 'size': '4870'}