"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"print(\"Std. deviation of star 0 is \", processed_data[0,:].std())\n",
"print(\"Std. deviation of star 1 is \", processed_data[1,:].std())\n",
"print(\"Std. deviation of star 2 is \", processed_data[2,:].std())\n",
"matplotlib.pyplot.plot(processed_data[0,:])\n",
"matplotlib.pyplot.plot(processed_data[1,:])\n",
"matplotlib.pyplot.plot(processed_data[2,:])\n",
"matplotlib.pyplot.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" \n",
"\n",
"
Check your understanding
\n",
"\n",
"\n",
"\n",
"> What variables refer to what values after each statement in the following program? Check your answer with the person next to you, then run the program in the cell below and see if you were correct.\n",
"```python\n",
"mass = 47.5\n",
"age = 122\n",
"mass = mass*2.0\n",
"age = age-20\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"collapsed": true,
"jupyter": {
"outputs_hidden": true
}
},
"outputs": [],
"source": [
"# INSERT YOUR CODE HERE"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" \n",
"\n",
"
Sorting out references
\n",
"\n",
"\n",
"\n",
"> What does the following program print out?\n",
"```python\n",
"first, second = 'Grace', 'Hopper'\n",
"third, fourth = second, first\n",
"print(third, fourth)\n",
"```\n",
"Run the code below and see if you were right."
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"collapsed": true,
"jupyter": {
"outputs_hidden": true
}
},
"outputs": [],
"source": [
"# INSERT YOUR CODE HERE"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" \n",
"\n",
"
Slicing strings
\n",
"\n",
"\n",
"\n",
">A section of an array is called a [slice](https://sheffield-mps.github.io/MPS227/bootcamp/reference/#slice). We can take slices of character strings as well:"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"first three characters: oxy\n",
"last three characters: gen\n"
]
}
],
"source": [
"element = 'oxygen'\n",
"print ('first three characters:', element[0:3])\n",
"print ('last three characters:', element[3:6])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"> What is the value of `element[:4]`?\n",
"> What about `element[4:]`?\n",
"> Or `element[:]`?\n",
">\n",
"> What is `element[-1]`?\n",
"> What is `element[-2]`?\n",
"> Given those answers,\n",
"> explain what `element[1:-1]` does."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" \n",
"\n",
"
Make your own plot
\n",
"\n",
"\n",
"\n",
">Create a plot showing the standard deviation (`numpy.std`) of each star against the star number"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}