Skip to content

Instantly share code, notes, and snippets.

@stephengruppetta
Created January 6, 2024 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephengruppetta/7127a666684c2f70d8c1398d50abcce6 to your computer and use it in GitHub Desktop.
Save stephengruppetta/7127a666684c2f70d8c1398d50abcce6 to your computer and use it in GitHub Desktop.
import random
import numpy as np
# Create a list of temperatures
temperatures = [
random.randint(-100, 350) / 10
for _ in range(1_000_000)
]
# And create a NumPy 'ndarray' from that list
temperatures_np = np.array(temperatures)
# Functions to convert from ºC to ºF
def convert_using_loop(data):
result = []
for temperature in data:
result.append(temperature * 1.8 + 32)
return result
def convert_using_numpy(data: np.ndarray):
return data * 1.8 + 32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment