62 numpy.ndarray: The patient's brain data.
63 """
64 # Load the patient's brain data from a file or database
65 brain_data = np.load("brain_data/{}.npy".format(patient_id))66
67 return brain_data
68
126
127 plt.figure()
128 plt.plot(
129 fpr, tpr, color="darkorange", lw=2, label="ROC curve (area = %0.2f)" % roc_auc130 )
131 plt.plot([0, 1], [0, 1], color="navy", lw=2, linestyle="--")
132 plt.xlim([0.0, 1.0])
92 num_devices = random.randint(1, 3)
93 devices = []
94 for i in range(num_devices):
95 device_name = 'Device {}'.format(i) 96 devices.append(device_name)
97 simulate_iot_device(device_name, sensor_data)
98
87 anomalies = analyze_sensor_data(sensor_data)
88 print('Anomalies detected:')
89 for i, j in anomalies:
90 print('Sensor {} at sample {}'.format(i, j)) 91 print()
92 num_devices = random.randint(1, 3)
93 devices = []
71 sensor_readings = {}
72 for i in range(sensor_data.shape[0]):
73 sensor_readings[i] = sensor_data[i][-1]
74 print('IoT device {} readings: {}'.format(name, sensor_readings)) 75
76# Define a function to simulate a sensor network
77def simulate_sensor_network(num_sensors, num_samples):
f-strings are the fastest way to format strings as compared to the following methods:
%
format()
str.join
+
operator to concatinate stringTemplate.substitute
Some less preferred ways to format strings are the following:
from string import Template
menu = ('eggs', 'spam', 42.4)
old_order = "%s and %s: %.2f ¤" % menu # [consider-using-f-string]
beginner_order = menu[0] + " and " + menu[1] + ": " + str(menu[2]) + " ¤"
joined_order = " and ".join(menu[:2])
format_order = "{} and {}: {:0.2f} ¤".format(menu[0], menu[1], menu[2])
named_format_order = "{eggs} and {spam}: {price:0.2f} ¤".format(eggs=menu[0], spam=menu[1], price=menu[2])
template_order = Template('$eggs and $spam: $price ¤').substitute(eggs=menu[0], spam=menu[1], price=menu[2])
Consider using f-strings as shown below:
menu = ('eggs', 'spam', 42.4)
f_string_order = f"{menu[0]} and {menu[1]}: {menu[2]:0.2f} ¤"