# Introduction to NumPy
This notebook serves as an introduction to NumPy.
### Topics Covered:
1. NumPy Arrays
2. Basic Operations
3. Indexing and Slicing
4. Vectorization
5. Linear Algebra
6. Random Number Generation
7. Data Manipulation
8. Statistical Computations
9. File Input and Output
10. Advanced Techniques
# Importing NumPy
import numpy as np
# Initialize NumPy arrays for examples
array1 = np.array([1, 2, 3, 4, 5])
array2 = np.array([5, 4, 3, 2, 1])
matrix1 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
# Example code will be added here
# Problem 1: Calculate Mean and Standard Deviation
Calculate the mean and standard deviation of a dataset using NumPy arrays.
# Example solution code:
# Calculate mean
# mean_value = np.mean(data)
# Calculate standard deviation
# std_dev = np.std(data)
# Hint: Use np.mean() and np.std() functions
# Problem 2: Element-wise Multiplication
Create a NumPy array of integers from 1 to 10 and perform element-wise multiplication with another array of the same size.
# Example solution code:
# Perform element-wise multiplication
# result_array = array1 * array2
# Hint: Use the * operator for element-wise multiplication
# Problem 3: Extract Every Second Element
Extract every second element from a NumPy array of numbers from 1 to 20.
# Example solution code:
# Extract every second element
# result_array = array[start:end:step]
# second_elements = array[1::2]
# Hint: Use array slicing with step argument
# Problem 4: Vectorized Sigmoid Function
Implement a vectorized function to calculate the sigmoid activation function for an array of numbers.
# Example solution code:
# Implement sigmoid function
# def sigmoid(x):
# return 1 / (1 + np.exp(-x))
# Apply sigmoid to an array
# sigmoid_values = sigmoid(array)
# Hint: Use np.exp() and arithmetic operations
# Problem 5: Solve a System of Linear Equations
Solve the system of linear equations:
1. 3x + 2y = 10
2. 4x - y = 5
# Example solution code:
# Define coefficients matrix and constants array
# coefficients = np.array([[3, 2], [4, -1]])
# constants = np.array([10, 5])
# Solve the equations
# solution = np.linalg.solve(coefficients, constants)
# print(solution)
# Hint: Use np.linalg.solve() function
# Problem 6: Generate Random Matrix
Generate a 3x3 matrix of random integers between 1 and 100 using NumPy.
# Example solution code:
# Generate random matrix
# random_matrix = np.random.randint(1, 101, size=(3, 3))
# Hint: Use np.random.randint() function
# Problem 7: Reshape NumPy Array
Reshape a 1D NumPy array into a 2D array (matrix) with 3 rows and 4 columns.
# Example solution code:
# Reshape array
# reshaped_array = np.reshape(array, (3, 4))
# Hint: Use np.reshape() function
# Problem 8: Calculate Correlation Coefficient
Calculate the correlation coefficient between two arrays of data using NumPy.
# Example solution code:
# Calculate correlation coefficient
# correlation_coeff = np.corrcoef(array1, array2)
# Hint: Use np.corrcoef() function
# Problem 9: Load Data from CSV
Load data from a CSV file into a NumPy array and perform basic statistics on the loaded data.
# Example solution code:
# Load data from CSV file
# data = np.loadtxt('data.csv', delimiter=',')
# Compute statistics
# mean_value = np.mean(data)
# std_dev = np.std(data)
# Hint: Use np.loadtxt() function