"A Python library for numerical computing that provides efficient operations on large arrays and matrices. The range of functions is similar to matlab\n",
"\n",
"* **Why Use NumPy Instead of Native Python** <br>\n",
"NumPy provides better performance, memory efficiency, and ease of use, making it the preferred choice for numerical computing tasks over native Python. <br>\n",
" * **Why is Numpy faster?** <br>\n",
" NumPy is written in C, a low-level programming language, which allows it to execute operations much faster than Python, which is an interpreted language."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Let's look at some numpy Code!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Numpy Arrays\n",
"* A NumPy array is a powerful data structure provided by the NumPy library, designed for numerical and scientific computing. It is similar to Python lists but much more efficient\n",
"<br>\n",
"<br>\n",
"* **Key characteristics of Numpy arrays**\n",
"\n",
" * **Fixed Size:**\n",
" Once created, the size of a NumPy array cannot change. This makes it more efficient compared to Python lists.\n",
"\n",
" * **Homogeneous Data:**\n",
" All elements in a NumPy array must be of the same data type (e.g., all integers or all floats). This allows NumPy to optimize memory usage and computation.\n",
"\n",
" * **N-Dimensional:**\n",
" NumPy arrays support multi-dimensional structures, making them suitable for handling vectors (1D), matrices (2D), or even tensors (3D and beyond)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating a NumPy Array\n",
"\n",
"* first we have to import the numpy library like the other libraries we used before we can do this with the import command ```import numpy as np``` with np beeing the short form of numpy.\n",
"\n",
"* a basic numpy array can be imported with ```np.array([1,2,3])``` \n",
"| **`np.random.rand`** | Create an array with random values (uniform). | `np.random.rand(2, 3)` | Random values like `[[0.5 0.7 0.1] [0.3 0.9 0.4]]` |\n",
"| **`np.random.randn`** | Create random values with normal distribution. | `np.random.randn(2, 3)` | Random values like `[[1.2 -0.4 0.8] [-0.7 1.5 0.3]]` |\n",
"| **`np.full`** | Create an array filled with a specific value. | `np.full((2, 3), 7)` | `[[7 7 7] [7 7 7]]` |\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"NumPy provides several ways to create arrays. Below are the most common methods:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Operation with numpy arrays\n",
"\n",
"* as with all libraries numpy comes with many built in functions let's have a look at the most common functions to manipulate numpy arrays "
A Python library for numerical computing that provides efficient operations on large arrays and matrices. The range of functions is similar to matlab
***Why Use NumPy Instead of Native Python**<br>
NumPy provides better performance, memory efficiency, and ease of use, making it the preferred choice for numerical computing tasks over native Python. <br>
***Why is Numpy faster?**<br>
NumPy is written in C, a low-level programming language, which allows it to execute operations much faster than Python, which is an interpreted language.
%% Cell type:markdown id: tags:
## Let's look at some numpy Code!
%% Cell type:markdown id: tags:
## Numpy Arrays
* A NumPy array is a powerful data structure provided by the NumPy library, designed for numerical and scientific computing. It is similar to Python lists but much more efficient
<br>
<br>
***Key characteristics of Numpy arrays**
* **Fixed Size:**
Once created, the size of a NumPy array cannot change. This makes it more efficient compared to Python lists.
* **Homogeneous Data:**
All elements in a NumPy array must be of the same data type (e.g., all integers or all floats). This allows NumPy to optimize memory usage and computation.
* **N-Dimensional:**
NumPy arrays support multi-dimensional structures, making them suitable for handling vectors (1D), matrices (2D), or even tensors (3D and beyond).
%% Cell type:markdown id: tags:
## Creating a NumPy Array
* first we have to import the numpy library like the other libraries we used before we can do this with the import command ```import numpy as np``` with np beeing the short form of numpy.
* a basic numpy array can be imported with ```np.array([1,2,3])```
| **`np.random.rand`** | Create an array with random values (uniform). | `np.random.rand(2, 3)` | Random values like `[[0.5 0.7 0.1] [0.3 0.9 0.4]]` |
| **`np.random.randn`** | Create random values with normal distribution. | `np.random.randn(2, 3)` | Random values like `[[1.2 -0.4 0.8] [-0.7 1.5 0.3]]` |
| **`np.full`** | Create an array filled with a specific value. | `np.full((2, 3), 7)` | `[[7 7 7] [7 7 7]]` |
%% Cell type:markdown id: tags:
NumPy provides several ways to create arrays. Below are the most common methods:
%% Cell type:markdown id: tags:
## Operation with numpy arrays
* as with all libraries numpy comes with many built in functions let's have a look at the most common functions to manipulate numpy arrays