Numerical Computing with NumPy

NumPy provides powerful N-dimensional array objects and tools for scientific computing. Essential for data analysis, machine learning, and numerical simulations.

Core Array Operations

# Create array
arr = np.array([1, 2, 3])
# Vectorized operations
squares = arr ** 2 # [1, 4, 9]
# Matrix operations
matrix = np.array([[1, 2], [3, 4]])
determinant = np.linalg.det(matrix)

Array Transformations

# Reshaping
arr = np.arange(6).reshape(2, 3)
# Stacking arrays
combined = np.vstack((a, b))

Random Sampling

# Normal distribution
samples = np.random.normal(0, 1, 100)

Practical Use Cases

Data Analysis

# Calculate summary stats
data = np.random.normal(50, 15, 1000)
mean, std = data.mean(), data.std()

Image Processing

# Convert RGB to grayscale
grayscale = np.dot(rgb_array, [0.299, 0.587, 0.114])

Your Task: Array Operations

Implement various NumPy operations:

  1. Create arrays and perform vector math
  2. Calculate dot product
  3. Flatten 2D array
  4. Generate random integers
Section 1/5Core Array Operations

Core Array Operations

Explore this concept

Numerical Computing with NumPy

NumPy provides powerful N-dimensional array objects and tools for scientific computing. Essential for data analysis, machine learning, and numerical simulations.

Core Array Operations

# Create array
arr = np.array([1, 2, 3])
# Vectorized operations
squares = arr ** 2 # [1, 4, 9]
# Matrix operations
matrix = np.array([[1, 2], [3, 4]])
determinant = np.linalg.det(matrix)

Output:

Click "Check" to run your code.