-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumpy.py
More file actions
38 lines (29 loc) · 1.08 KB
/
Copy pathnumpy.py
File metadata and controls
38 lines (29 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import numpy as np
import scipy.stats
# Task 1: Scalar Broadcasting
vector = np.arange(1, 11) + 1
# Task 2: Matrix Broadcasting
matrix = vector[:, np.newaxis] + vector
# Task 3: Standardizing Data
data = np.exp(np.random.randn(50, 5))
mean = np.mean(data, axis=0)
std = np.std(data, axis=0)
# Task 4: Standardize the Data
normalized = (data - mean) / std
normalized_mean = np.mean(normalized, axis=0)
normalized_std = np.std(normalized, axis=0)
# Task 5: Print Mean and Standard Deviation of Normalized Data
print("Mean of Normalized Data:")
print(normalized_mean)
print("\nStandard Deviation of Normalized Data:")
print(normalized_std)
# Task: Chi-squared Hypothesis Testing
observed = np.array([[141, 68, 4],
[179, 159, 7],
[220, 216, 4],
[86, 101, 4]])
chi2, p, dof, expected = scipy.stats.chi2_contingency(observed)
if p < 0.05:
print("There is evidence of a relationship between age group and movie genre inclination.")
else:
print("There is no evidence of a relationship between age group and movie genre inclination.")