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