#Program for adding two elements of list
List1 = [1,2,3]
List2 = [1,2,3]
#creating a newlist
newList = []
for n in range(0, len(List1)):
[Link](List1[n] + List2[n])
print(newList)
NumPy
The full form of NumPy is Numerical Python. It is a popular library in Python used
for working with arrays, matrices, and performing a wide range of mathematical
and statistical operations.
Statistical Functions
MEAN
The mean gives the arithmetic mean of the input values. It’s a measure of central
tendency that provides the “average” value. It calculates by taking the sum of
elements divided by the total number of elements.
import numpy as np
array = [Link](20)
print(array)
r1 = [Link](array)
print("\nMean: ", r1)
MEDIAN
The median is the middle value when the data is sorted. If the dataset has an odd
number of values, the median is the exact middle element. If the dataset has an
even number of values, the median is the average of the two middle values.
import numpy as np
array = [Link](20)
print(array)
r1 = [Link](array)
print("\nstd: ", r1)
MODE
The mode is the value that appears most frequently in a dataset. If several values
occur with the same highest frequency, a dataset can have multiple modes
(multimodal).
import numpy as np
from scipy import stats
data = [Link]([3, 4, 4, 5, 6, 7, 8, 4])
print(data)
# Compute mode
mode_value = [Link](data)
print(f"Mode: {mode_value.mode[0]}, Count: {mode_value.count[0]}")
What is Matplotlib in Python?
Matplotlib is a popular data visualization library in Python. It's often used for creating static,
interactive, and animated visualizations in Python. Matplotlib allows you to generate plots,
histograms, bar charts, scatter plots, etc., with just a few lines of code.
Write a program to display line chart from (2,5) to (9,10).
import [Link] as plt
# Define the x and y coordinates of the two points
x_coordinates = [2, 9]
y_coordinates = [5, 10]
# Create the line chart
[Link](x_coordinates, y_coordinates)
# Add labels and a title for clarity
[Link]("X-axis")
[Link]("Y-axis")
[Link]("Line Chart from (2, 5) to (9, 10)")
# Display the chart
[Link](True) # Optional: Add a grid for better readability
[Link]()
Write a program to display a scatter chart for the following points (2,5),
(9,10),(8,3),(5,7),(6,18).
import [Link] as plt
# Define the given points
points = [(2, 5), (9, 10), (8, 3), (5, 7), (6, 18)]
# Separate x and y coordinates into individual lists
x_values = [point[0] for point in points]
y_values = [point[1] for point in points]
# Create the scatter plot
[Link](x_values, y_values, color='blue', marker='o')
# Add labels and a title to the chart
[Link]('Scatter Chart for Given Points')
[Link]('X-axis')
[Link]('Y-axis')
# Add a grid for better readability (optional)
[Link](True)
# Display the plot
[Link]()