import numpy as np # Sample Numpy Array arr = np.array([1, 2, 3, 4, 5]) print("Array:", arr)
import numpy as np # Original array arr = np.array([1, 2, 3, 4, 5]) # Removing an element arr = np.delete(arr, 2) # Removing the element at index 2 print("Array after removing element:", arr) # Changing an element arr[1] = 10 # Changing the element at index 1 print("Array after changing element:", arr) # Inserting an element arr = np.insert(arr, 3, 15) # Inserting 15 at index 3 print("Array after inserting element:", arr)
import numpy as np # Creating sample arrays arr1 = np.array([1, 2, 3, 4, 5]) arr2 = np.array([6, 7, 8, 9, 10]) # Addition add_result = np.add(arr1, arr2) print("Addition:", add_result) # Subtraction sub_result = np.subtract(arr2, arr1) print("Subtraction:", sub_result) # Multiplication mul_result = np.multiply(arr1, arr2) print("Multiplication:", mul_result) # Division div_result = np.divide(arr2, arr1) print("Division:", div_result)
import numpy as np # Creating a sample array arr = np.array([0, np.pi/4, np.pi/2]) # Trigonometric functions sin_result = np.sin(arr) print("Sine:", sin_result) cos_result = np.cos(arr) print("Cosine:", cos_result) # Exponential and logarithmic functions exp_result = np.exp(arr) print("Exponential:", exp_result) log_result = np.log(arr) print("Natural logarithm:", log_result)
import numpy as np # Sample dataset data = np.array([2, 4, 6, 8, 10, 4, 4, 8, 10]) # Mean mean = np.mean(data) print("Mean:", mean) # Median median = np.median(data) print("Median:", median) # Mode counts = np.bincount(data) mode = np.argmax(counts) print("Mode:", mode)
import numpy as np # Sample dataset data = np.array([2, 4, 6, 8, 10, 4, 4, 8, 10]) # Standard deviation std_dev = np.std(data) print("Standard Deviation:", std_dev) # Variance variance = np.var(data) print("Variance:", variance) # Correlation coefficient corr_coef = np.corrcoef(data) print("Correlation Coefficient:", corr_coef)
import numpy as np # Dot product vector1 = np.array([1, 2, 3]) vector2 = np.array([4, 5, 6]) dot_product = np.dot(vector1, vector2) print("Dot Product:", dot_product) # Cross product vector3 = np.array([2, -3, 1]) vector4 = np.array([5, 2, 4]) cross_product = np.cross(vector3, vector4) print("Cross Product:", cross_product) # Matrix inversion matrix = np.array([[1, 2], [3, 4]]) inverse_matrix = np.linalg.inv(matrix) print("Inverse Matrix:\n", inverse_matrix)
import numpy as np import matplotlib.pyplot as plt # Generate data x = np.linspace(0, 10, 100) y = np.sin(x) # Line plot plt.plot(x, y) plt.title("Line Plot") plt.xlabel("x") plt.ylabel("y") plt.show()
# Bar plot x_categories = ['A', 'B', 'C', 'D'] y_values = [20, 35, 30, 25] plt.bar(x_categories, y_values) plt.title("Bar Plot") plt.xlabel("Categories") plt.ylabel("Values") plt.show()
# Scatter plot plt.scatter(x, y) plt.title("Scatter Plot") plt.xlabel("x") plt.ylabel("y") plt.show()
data = np.random.randn(1000) plt.hist(data, bins=30) plt.title("Histogram") plt.xlabel("Value") plt.ylabel("Frequency") plt.show()
Leave A Comment