{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Problem 1\n", "Import the NumPy library under the alias `np`." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Problem 2\n", "Add `2` to every element of the following NumPy array." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 4, 5, 6, 11, 9, 7, 10, 4])" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr = np.array([2,3,4,9,7,5,8,2])\n", "arr+2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Problem 3\n", "Double the value of every element in `arr` by adding it to itself." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 4, 6, 8, 18, 14, 10, 16, 4])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr + arr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Problem 4\n", "Create an array of zeros by subtracting `arr` from itself." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0, 0, 0, 0, 0, 0, 0, 0])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr - arr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Problem 5\n", "Multiply every element in `arr` by 6." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([12, 18, 24, 54, 42, 30, 48, 12])" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr * 6" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Problem 6\n", "Divide every element in `arr` by 4." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0.5 , 0.75, 1. , 2.25, 1.75, 1.25, 2. , 0.5 ])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr / 4" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Problem 7\n", "Create an array of ones by dividing every element in `arr` by itself." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1., 1., 1., 1., 1., 1., 1., 1.])" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr / arr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Problem 8\n", "Calculate the square root of every element in `arr`. Do not use the `**` operator." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1.41421356, 1.73205081, 2. , 3. , 2.64575131,\n", " 2.23606798, 2.82842712, 1.41421356])" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.sqrt(arr)" ] } ], "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": 4 }