Created
November 20, 2019 16:46
-
-
Save AshutoshDash1999/d8e0ddcb0fc9b7f17d2031a1c717f0d9 to your computer and use it in GitHub Desktop.
Created on Cognitive Class Labs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "<h3> Get to Know a numpy Array </h3>" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "cast the following list to a numpy array:" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([1, 2, 3, 4, 5])" | |
| ] | |
| }, | |
| "execution_count": 2, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "import numpy as np\n", | |
| "a=[1,2,3,4,5]\n", | |
| "a = np.array(a)\n", | |
| "a\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "1) type using the function type " | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 3, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "numpy.ndarray" | |
| ] | |
| }, | |
| "execution_count": 3, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "type(a)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "2) the shape of the array " | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "(5,)" | |
| ] | |
| }, | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "np.shape(a)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 7, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "dtype('int64')" | |
| ] | |
| }, | |
| "execution_count": 7, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "a.dtype" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "3) the type of data in the array " | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": false, | |
| "jupyter": { | |
| "outputs_hidden": false | |
| } | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "4) find the mean of the array " | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 9, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "3.0" | |
| ] | |
| }, | |
| "execution_count": 9, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "a = np.mean(a)\n", | |
| "a" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "<h3> Creating and Plotting Functions </h3>" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "1) create the following functions using the numpy array <code> x </code>" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "$$y=sin(x)+2$$" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 14, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([ 0.00000000e+00, 6.34239197e-02, 1.26592454e-01, 1.89251244e-01,\n", | |
| " 2.51147987e-01, 3.12033446e-01, 3.71662456e-01, 4.29794912e-01,\n", | |
| " 4.86196736e-01, 5.40640817e-01, 5.92907929e-01, 6.42787610e-01,\n", | |
| " 6.90079011e-01, 7.34591709e-01, 7.76146464e-01, 8.14575952e-01,\n", | |
| " 8.49725430e-01, 8.81453363e-01, 9.09631995e-01, 9.34147860e-01,\n", | |
| " 9.54902241e-01, 9.71811568e-01, 9.84807753e-01, 9.93838464e-01,\n", | |
| " 9.98867339e-01, 9.99874128e-01, 9.96854776e-01, 9.89821442e-01,\n", | |
| " 9.78802446e-01, 9.63842159e-01, 9.45000819e-01, 9.22354294e-01,\n", | |
| " 8.95993774e-01, 8.66025404e-01, 8.32569855e-01, 7.95761841e-01,\n", | |
| " 7.55749574e-01, 7.12694171e-01, 6.66769001e-01, 6.18158986e-01,\n", | |
| " 5.67059864e-01, 5.13677392e-01, 4.58226522e-01, 4.00930535e-01,\n", | |
| " 3.42020143e-01, 2.81732557e-01, 2.20310533e-01, 1.58001396e-01,\n", | |
| " 9.50560433e-02, 3.17279335e-02, -3.17279335e-02, -9.50560433e-02,\n", | |
| " -1.58001396e-01, -2.20310533e-01, -2.81732557e-01, -3.42020143e-01,\n", | |
| " -4.00930535e-01, -4.58226522e-01, -5.13677392e-01, -5.67059864e-01,\n", | |
| " -6.18158986e-01, -6.66769001e-01, -7.12694171e-01, -7.55749574e-01,\n", | |
| " -7.95761841e-01, -8.32569855e-01, -8.66025404e-01, -8.95993774e-01,\n", | |
| " -9.22354294e-01, -9.45000819e-01, -9.63842159e-01, -9.78802446e-01,\n", | |
| " -9.89821442e-01, -9.96854776e-01, -9.99874128e-01, -9.98867339e-01,\n", | |
| " -9.93838464e-01, -9.84807753e-01, -9.71811568e-01, -9.54902241e-01,\n", | |
| " -9.34147860e-01, -9.09631995e-01, -8.81453363e-01, -8.49725430e-01,\n", | |
| " -8.14575952e-01, -7.76146464e-01, -7.34591709e-01, -6.90079011e-01,\n", | |
| " -6.42787610e-01, -5.92907929e-01, -5.40640817e-01, -4.86196736e-01,\n", | |
| " -4.29794912e-01, -3.71662456e-01, -3.12033446e-01, -2.51147987e-01,\n", | |
| " -1.89251244e-01, -1.26592454e-01, -6.34239197e-02, -2.44929360e-16])" | |
| ] | |
| }, | |
| "execution_count": 14, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "x=np.linspace(0,2*np.pi,100)\n", | |
| "x\n", | |
| "y = np.sin(x)\n", | |
| "y\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "2) plot the function" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import matplotlib.pyplot as plt\n", | |
| "%matplotlib inline \n", | |
| "\n", | |
| "\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "<hr>\n", | |
| "<small>Copyright © 2018 IBM Cognitive Class. This notebook and its source code are released under the terms of the [MIT License](https://cognitiveclass.ai/mit-license/).</small>" | |
| ] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python", | |
| "language": "python", | |
| "name": "conda-env-python-py" | |
| }, | |
| "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.6.7" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 4 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment