Answer To: { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## NumPy\n", "For each question...
Devanshu answered on Mar 31 2021
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## NumPy\n",
"For each question below, use NumPy functionality to execute the logic of your answer. (**Do not use ```For``` loops!**)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Generating Random Data and Filtering That Data\n",
"\n",
"Please run the two cells below to set your random seed. (This makes the 'randomness' of the array the same for everyone)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"np.random.seed(25)\n",
"ar = np.random.randn(1000)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 22, 102, -83, -59, -95, -22, -61, -73, 51, 86, -92,\n",
" -23, -41, 123, 7, -124, 120, -104, 105, -41, -27, -3,\n",
" 26, 68, 99, 59, 53, -29, -51, -58, 22, 73, -96,\n",
" 38, 39, 40, 21, -63, 24, 63, 11, 68, 24, -70,\n",
" 36, -50, -22, -56, 10, -55, 109, -90, -62, -94, 117,\n",
" -37, -54, 28, -20, 118, 72, -22, 94, 31, -116, 31,\n",
" 47, 57, 50, -62, -34, 50, 76, 112, 16, -96, 49,\n",
" -55, -8, -60, -6, -85, 42, -27, 119, -9, 83, -78,\n",
" 104, -64, 67, -9, 121, 49, -114, -53, -91, -21, 19,\n",
" -32, 84, 76, 44, 43, 102, -58, 4, 56, -114, 0,\n",
" -29, 23, 67, 122, -60, -16, -65, -19, 17, 3, -126,\n",
" -53, 52, 38, -76, -5, -24, 20, -30, 15, 3, -32,\n",
" -77, -33, 54, -115, -74, 101, 96, -18, -54, -109, 43,\n",
" -73, 16, -67, -16, -54, -35, -88, 9, 112, -45, 87,\n",
" -114, -85, 93, -17, 41, -28, -90, 48, -4, 64, 1,\n",
" -97, 59, -126, -100, -48, 39, 62, 53, 37, -52, 30,\n",
" -66, -19, 92, -84, -77, -120, -87, -128, 63, 50, -39,\n",
" -64, -50, 101, -118, 40, -126, 90, 73, -126, 120, -36,\n",
" 87, 84, -121, 111, -103, -44, 5, -56, 0, 17, 97,\n",
" -70, 11, 64, 1, -43, -6, -6, -39, 40, -74, -65,\n",
" -16, -115, 25, -98, 98, -53, -26, -115, -14, 106, 54,\n",
" -118, -28, -99, 96, 80, -56, -92, -41, 0, 47, 71,\n",
" -96, 45, -11, -118, -108, -108, 59, 8, -88, 30, 59,\n",
" -17, 73, 14, -15, 24, -26, -37, 34, -102, 57, -126,\n",
" 8, -82, 68, -103, -111, 9, 15, -79, -59, -55, 65,\n",
" -20, 120, -83, -40, 69, -57, 61, 19, 117, 11, 94,\n",
" 15, -125, -117, 4, -110, -37, -50, 102, 27, -64, -17,\n",
" -17, 28, 2, -124, -25, -89, -88, 2, 41, 31, 93,\n",
" 77, 40, -116, 66, -6, -113, 64, 1, 58, 57, 7,\n",
" -44, 3, -109, 74, 111, -23, -87, 23, -80, 21, 83,\n",
" -60, 6, 126, 27, -60, -118, -29, -119, -120, 17, 73,\n",
" -1, -114, -7, 111, 8, 28, 35, -54, 111, -110, -12,\n",
" -1, 46, -54, 2, 70, 14, -37, 46, 88, -61, 121,\n",
" 74, 88, -30, 89, -50, 4, 124, -59, -65, 89, 23,\n",
" 82, -70, 98, -9, -67, -31, -6, 43, 11, -12, 0,\n",
" -18, 47, 58, 72, 98, -20, 94, 6, -10, 106, 43,\n",
" 66, -77, 58, 94, 100, -97, -103, -104, 12, 78, 55,\n",
" -40, 78, -65, -117, 47, -98, 78, 8, 45, 20, -110,\n",
" 16, 21, 64, 71, -51, -52, -97, -100, 22, -109, -45,\n",
" 53, -6, -27, -127, 6, -51, -51, 45, -2, 24, 86,\n",
" -103, 57, -18, -93, -127, -117, 55, -108, 119, -23, 35,\n",
" 125, 68, -39, 54, -74, -46, -121, -7, 37, -33, -20,\n",
" -86, -117, 74, 22, 72, 61, 60, -46, 105, 27, -12,\n",
" -28, -31, 61, 40, -125, 4, 6, -77, -30, 116, -35,\n",
" 89, 63, 80, -103, -28, -112, 43, -97, -70, -41, 123,\n",
" -25, -92, -59, 41, -45, -77, -24, -21, 117, 68, 0,\n",
" 69, 17, 62, 50, 42, -5, 71, 5, 56, ...