-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumpyFunction1.py
More file actions
38 lines (31 loc) · 1.04 KB
/
NumpyFunction1.py
File metadata and controls
38 lines (31 loc) · 1.04 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
"""Suppose you have a dataset containing daily temperature readings for
a city, and you want to identify days with extreme temperature conditions.
Find days where the temperature either exceeded 35
degrees Celsius (hot day) or dropped below 5 degrees Celsius (cold day)."""
import numpy as np
# Given temperature data
temperatures = np.array([32.5, 34.2, 36.8, 29.3, 31.0, 38.7, 23.1, 18.5, 22.8, 37.2,-2.0,4.0,-3.0])
# Identify hot days (temperatures > 35°C) using np.where()
hot_days = np.where(temperatures > 35)[0]
# Identify cold days (temperatures < 5°C) using np.where()
cold_days = np.where(temperatures < 5)[0]
# Display the results
print("Hot Days:")
print("Day\tTemperature(°C)")
for index in hot_days:
print(f"{index + 1}\t{temperatures[index]}")
print("\nCold Days:")
print("Day\tTemperature(°C)")
for index in cold_days:
print(f"{index + 1}\t{temperatures[index]}")
""" Output:-
Hot Days:
Day Temperature(°C)
3 36.8
6 38.7
10 37.2
Cold Days:
Day Temperature(°C)
11 -2.0
12 4.0
13 -3.0 """