Jupyter Notebook is a powerful interactive environment that combines code execution, documentation, and visualization in a single interface. It’s an excellent tool for exploring Python concepts and experimenting with different libraries, including NumPy.
Key Features of Jupyter Notebook
- Interactive Cells: Jupyter Notebooks are divided into cells, which can contain code, text, or Markdown. This allows for a flexible and interactive workflow.
- Code Execution: You can execute code within cells and see the results immediately, making it easy to experiment and learn.
- Markdown Support: Markdown is a lightweight markup language used for formatting text and creating rich content within notebooks.
- Visualization: Jupyter Notebooks can be used to create visualizations using libraries like Matplotlib, Seaborn, and Plotly.
- Sharing and Collaboration: Notebooks can be easily shared and collaborated on, making them ideal for teaching, research, and data science projects.
Python Basics Review
Data Types:
- Numbers: Integers (e.g., 1, 2, -3), floating-point numbers (e.g., 3.14, 2.718), and complex numbers (e.g., 2+3j).
- Strings: Sequences of characters enclosed in quotes (e.g., “Hello”, ‘world’).
- Lists: Ordered collections of elements (e.g., [1, 2, 3, “hello”]).
- Tuples: Immutable sequences of elements (e.g., (1, 2, 3)).
- Dictionaries: Unordered collections of key-value pairs (e.g., {‘name’: ‘Alice’, ‘age’: 30}).
Operators:
- Arithmetic: +, -, *, /, // (floor division), % (modulo), ** (exponentiation).
- Comparison: ==, !=, <, >, <=, >=.
- Logical: and, or, not.
Control Flow:
- if statements: Execute code conditionally.
- for loops: Iterate over a sequence of elements.
- while loops: Execute code repeatedly until a condition is met.
Functions:
- Define reusable blocks of code.
- Take input parameters and return values.
NumPy Basics in Jupyter
Creating Arrays:
Python
import numpy as np
# Create a 1D array
arr1d = np.array([1, 2, 3])
# Create a 2D array
arr2d = np.array([[1, 2], [3, 4]])
Array Operations:
Python
# Element-wise addition
result = arr1d + arr2d
# Matrix multiplication
result = np.dot(arr2d, arr2d.T)
Indexing and Slicing:
Python
# Access an element
element = arr1d[0]
# Slice a portion of the array
slice = arr1d[1:3]
Shape Manipulation:
Python
# Reshape an array
reshaped = arr2d.reshape(4, 1)
# Transpose an array
transposed = arr2d.T
By combining Jupyter Notebook’s interactive features with the powerful capabilities of NumPy, you can effectively explore and understand Python basics while gaining practical experience in numerical computing.