0% found this document useful (0 votes)
128 views9 pages

NumPy Exercises for Beginners

The document contains a series of exercises to test knowledge of NumPy. It includes tasks to create arrays and matrices with different properties like random numbers, identities, and linear spacing. It also includes reproducing the output of code cells that demonstrate NumPy indexing and selection. The goal is to write code that can replicate the outputs without directly running the example cells.

Uploaded by

Vaibhav Arora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views9 pages

NumPy Exercises for Beginners

The document contains a series of exercises to test knowledge of NumPy. It includes tasks to create arrays and matrices with different properties like random numbers, identities, and linear spacing. It also includes reproducing the output of code cells that demonstrate NumPy indexing and selection. The goal is to write code that can replicate the outputs without directly running the example cells.

Uploaded by

Vaibhav Arora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

{

"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "8A5O0B6OzJMf"
},
"source": [
"# NumPy Exercises \n",
"\n",
"Now that we've learned about NumPy let's test your knowledge. We'll start
off with a few simple tasks, and then you'll be asked some more complicated
questions."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "TMwNPgUzzJMk"
},
"source": [
"#### Import NumPy as np"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "fDgY9QxqzJMk"
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "tui6tu0YzJMl"
},
"source": [
"#### Create an array of 10 zeros "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "D7pePmDqzJMl"
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "mAPcohujzJMl"
},
"source": [
"#### Create an array of 10 ones"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "oIf4w9zCzJMl"
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "zR2kFC_EzJMm"
},
"source": [
"#### Create an array of 10 fives"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "AnMTy9h8zJMm"
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "S_knGh2_zJMm"
},
"source": [
"#### Create an array of the integers from 10 to 50"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "MwcKcGtgzJMn"
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "sSkS5w3zzJMn"
},
"source": [
"#### Create an array of all the even integers from 10 to 50"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "-0JBle3UzJMo"
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "TIF6aCYXzJMo"
},
"source": [
"#### Create a 3x3 matrix with values ranging from 0 to 8"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "BeuEGj3SzJMo"
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "FXvF6OAtzJMo"
},
"source": [
"#### Create a 3x3 identity matrix"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "WSdpL7qzzJMo"
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "LUG29slSzJMo"
},
"source": [
"#### Use NumPy to generate a random number between 0 and 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "qDTGiLbizJMp"
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "jLlpCoUpzJMp"
},
"source": [
"#### Use NumPy to generate an array of 25 random numbers sampled from a
standard normal distribution"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "KHuQ8Wj0zJMp"
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "HOUFRIexzJMp"
},
"source": [
"#### Create the following matrix:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "5uLN7mGezJMp"
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "8878yDRozJMq"
},
"source": [
" Create an array of 20 linearly spaced points between 0 and 1:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "3gEtEcIqzJMq"
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "YfYf93HyzJMq"
},
"source": [
"## Numpy Indexing and Selection\n",
"\n",
"Now you will be given a few matrices, and be asked to replicate the
resulting matrix outputs:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"id": "_b52j7F7zJMq"
},
"outputs": [],
"source": [
"# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW\n",
"# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T\n",
"# BE ABLE TO SEE THE OUTPUT ANY MORE"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 0
},
"id": "L3oB2nGKzJMq",
"outputId": "6d94156d-f076-4360-8338-7f0931cfdcd7"
},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 1, 2, 3, 4, 5],\n",
" [ 6, 7, 8, 9, 10],\n",
" [11, 12, 13, 14, 15],\n",
" [16, 17, 18, 19, 20],\n",
" [21, 22, 23, 24, 25]])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mat = np.arange(1,26).reshape(5,5)\n",
"mat"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"id": "S2MAY1RG1Khb"
},
"outputs": [],
"source": [
"# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW\n",
"# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T\n",
"# BE ABLE TO SEE THE OUTPUT ANY MORE"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 0
},
"id": "2rRRhjgk1Khj",
"outputId": "5b073241-9911-4dc0-f504-a06f7b82e8d0"
},
"outputs": [
{
"data": {
"text/plain": [
"array([[12, 13, 14, 15],\n",
" [17, 18, 19, 20],\n",
" [22, 23, 24, 25]])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"id": "YiuSm2GdzJMr"
},
"outputs": [],
"source": [
"# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW\n",
"# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T\n",
"# BE ABLE TO SEE THE OUTPUT ANY MORE"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "DISUEBUQzJMr",
"outputId": "33c48088-a981-4968-b250-1b67634e2c24"
},
"outputs": [
{
"data": {
"text/plain": [
"20"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"id": "S7zOZdvmzJMr"
},
"outputs": [],
"source": [
"# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW\n",
"# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T\n",
"# BE ABLE TO SEE THE OUTPUT ANY MORE"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "DGpPQCIvzJMr",
"outputId": "ab49d5ce-70e1-4842-cb65-f176cb5b2749"
},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 2],\n",
" [ 7],\n",
" [12]])"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"id": "xijEv0K2zJMr"
},
"outputs": [],
"source": [
"# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW\n",
"# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T\n",
"# BE ABLE TO SEE THE OUTPUT ANY MORE"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "D0EGP1N3zJMs",
"outputId": "98308623-2e17-4902-a614-d198ac35efe6"
},
"outputs": [
{
"data": {
"text/plain": [
"array([21, 22, 23, 24, 25])"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"id": "eR9WZAMFzJMs"
},
"outputs": [],
"source": [
"# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW\n",
"# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T\n",
"# BE ABLE TO SEE THE OUTPUT ANY MORE"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "dNVjyFtTzJMs",
"outputId": "5ffb5934-c55e-44b2-efba-e9cfd621faee"
},
"outputs": [
{
"data": {
"text/plain": [
"array([[16, 17, 18, 19, 20],\n",
" [21, 22, 23, 24, 25]])"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
}
],
"metadata": {
"colab": {
"name": "Assignment 9.ipynb",
"provenance": []
},
"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.4"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

You might also like