NumPy_Presentation - Copy
NumPy_Presentation - Copy
• Verify installation:
• ```python
• import numpy
• print(numpy.__version__)
Understanding NumPy Arrays
• • NumPy arrays are more efficient than
Python lists.
• • Example:
• ```python
• import numpy as np
• arr = np.array([1, 2, 3])
• print(arr)
• ```
Creating Arrays
• Examples:
• ```python
• np.array([1, 2, 3]) # 1D Array
• np.array([[1, 2], [3, 4]]) # 2D Array
• np.zeros((2, 2)) # Zeroes
• np.ones((3, 3)) # Ones
• np.arange(1, 10, 2) # Range
• ```
Array Indexing and Slicing
• Example:
• ```python
• arr = np.array([10, 20, 30, 40])
• print(arr[1]) # Access single element
• print(arr[1:3]) # Slice elements
• ```