{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Generating Data with Numpy"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1. Run these next few cells:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"array_1D = np.array([10,11,12,13, 14])\n",
"array_1D"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"array_2D = np.array([[20,30,40,50,60], [43,54,65,76,87], [11,22,33,44,55]])\n",
"array_2D"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"array_3D = np.array([[[1,2,3,4,5], [11,21,31,41,51]], [[11,12,13,14,15], [51,52,53,54,5]]])\n",
"array_3D"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2. Generate 4 arrays of size 10:\n",
" A) The first one should be \"empty\"\n",
" B) The second one should be full of 0s\n",
" C) The third one should be full of 1s\n",
" D) The last one should be full of 2s\n",
" (Hint: Try to use 4 different functions here.)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3. Generate 4 more arrays. This time, they should be 2 by 4 arrays. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 4. Use the _like functions to generate 4 more arrays:\n",
" A) An empty array with the same shape as array_1D. \n",
" B) An 2-D array of 0s with the same shape as array_2D.\n",
" C) A 3-D array of 1s with the same shappe as array_3D.\n",
" D) A 3-D array of 2s with the same shape as array_3D. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 5. With the help of the np.arange() function, generate several sequences of numbers:\n",
" A) The integers from 0 to 50, excluding 50. \n",
" B) The integers from 1 to 50, including 50. \n",
" C) The integers from 25 to 50, including 50. \n",
" D) Every 5-th integers from 25 to 50, including 50. \n",
" E) Every 5-th integers from 25 to 50, including 50, represented as decimals of up to 32 bits. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 6. Import the following functions from the numpy.random module:\n",
" A) Generator as \"gen\".\n",
" B) PCG64 as \"pcg\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 7. Create a random generator object."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 8. Using the .random() method, generate the following pseudo-random values:\n",
" A) A single probability of an event occuring.\n",
" B) An array of size 10 with the probabilities of 10 events. \n",
" C) A 5 by 10 2-D array with the probabilities of 50 events. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 9. Set the seed for the random generator to 123, and generate the same 3 sets of values:\n",
" A) A single probability of an event occuring.\n",
" B) An array of size 10 with the probabilities of 10 events. \n",
" C) A 5 by 10 2-D array with the probabilities of 50 events. \n",
" Note: The seed only lasts for a single method before it gets reset. Hence, make sure you define the seed before calling the method every time. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 10. Set the seed for the random generator to 123, and generate the following arrays of integers:\n",
" A) A single integer between 0 and 10.\n",
" B) A 1-D array of 10 integers between 0 and 100.\n",
" C) A 5 by 10 array of two-digit integers."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 11. For this next bit, check the NumPy documentation and select 3 different probability distributions (e.g. normal, poisson, binomial, logistic) and generate the following:\n",
" A) One \"default\" value from one distribution (without specifying any non-mandatory arguments).\n",
" B) An array of 10 values from the second distribution. \n",
" C) A 5 by 10 2-D array with values from the third distribution."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}