9. Practical Python – Advanced Topics
Activity 23: Generating a List of Random Numbers in a Python Virtual Environment
Solution
- Create a new
conda
environment calledmy_env
:conda create -n my_env
You should get the following output:
- Activate the
conda
environment:conda activate my_env
- Install
numpy
in your new environment:conda install numpy
You should get the following output:
- Next, install and run a
jupyter
Notebook from within your virtual environment:conda install jupyter jupyter notebook
- Create a new
jupyter
Notebook and start with the following imports:import threading import queue import cProfile import itertools import numpy as np
- Create a function that uses the
numpy
library to generate an array of random numbers. Recall that when threading, we need to be able to send a signal for thewhile
statement to terminate:in_queue = queue.Queue(...