{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Recitation1-Test2 (35 marks)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a matrix **A** of size (3,5) with 0 mean and 5 standard deviation. (**1 mark**)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set all the elements in first row of **A** to 7. (**1 mark**)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set all the elements in second row of **A** to -2. Set the element in third row and second column of **A** to 9. (**2 marks**) " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a vector **a** of size 30 with values ranging from 60 to 89. (**2 marks**) " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a (5,5) matrix **M** with values ranging from 0 to 24. (**1 mark**) " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make a (3,3) matrix **N** with 5 on the border and 0 inside. (**1 mark**) " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a matrix **P** of size (3,4) with random integer values. (**1 mark**) " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Subtract the mean of each row of matrix **A**. (**1 mark**) " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**listA** = [1,2,3,4,5,6,7,8,9,10] \n", "\n", "If an element of **listA** is smaller than 5, replace it with 0. And if an element of x is bigger than 5, replace it with 1. (**3 marks**) " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compute the square of **listA** elements in one line. (**2 marks**) " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Concatenate b1 and b2. (**2 marks**) " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "b1 = np.array(['Hello', 'in','first'])\n", "b2 = np.array(['Students','the','recitation'])\n", "combine_b = " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Split the element of combine_b (above list) with spaces. (**2 marks**) " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a 3-D array **L** with five on the diagonal and zeros elsewhere. (**1 mark**) " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make a function that can print a dictionary where the keys are numbers between 1 and 5 and the values are square of keys. (**2 marks**) " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a dictionary of student **Ali** where the keys are courses and values are total and obtaining marks in each course. Save this dictionary in a text file and numpy file. (**4 marks**) " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a class 'calculator' with the following functions to compute: **(9 marks)**\n", "- the dot product between two vectors\n", "- the cross product between two vectors\n", "- the length (norm) of the vector\n", "- matrix-vector product of **M** and **v**\n", "- the mean squared error between **u**  and **v**\n", "- the unit norm of vector **u**" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "M = np.array([5,2,4],[2,9,8],[2,1,7]])\n", "u = np.array([1,5,2])\n", "v = np.array([4,2,3])\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "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.6.9" } }, "nbformat": 4, "nbformat_minor": 2 }