<!DOCTYPE html> <html> <head> <meta name="databricks-html-version" content="1"> <title>017_LAlgIntro - Databricks</title> <meta charset="utf-8"> <meta name="google" content="notranslate"> <meta http-equiv="Content-Language" content="en"> <meta http-equiv="Content-Type" content="text/html; charset=UTF8"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Code+Pro:400,700"> <link rel="stylesheet" type="text/css" href="https://databricks-prod-cloudfront.cloud.databricks.com/static/201602081754420800-0c2673ac858e227cad536fdb45d140aeded238db/lib/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="https://databricks-prod-cloudfront.cloud.databricks.com/static/201602081754420800-0c2673ac858e227cad536fdb45d140aeded238db/lib/jquery-ui-bundle/jquery-ui.min.css"> <link rel="stylesheet" type="text/css" href="https://databricks-prod-cloudfront.cloud.databricks.com/static/201602081754420800-0c2673ac858e227cad536fdb45d140aeded238db/css/main.css"> <link rel="stylesheet" href="https://databricks-prod-cloudfront.cloud.databricks.com/static/201602081754420800-0c2673ac858e227cad536fdb45d140aeded238db/css/print.css" media="print"> <link rel="icon" type="image/png" href="https://databricks-prod-cloudfront.cloud.databricks.com/static/201602081754420800-0c2673ac858e227cad536fdb45d140aeded238db/img/favicon.ico"/> <script>window.settings = {"sparkDocsSearchGoogleCx":"004588677886978090460:_rj0wilqwdm","dbcForumURL":"http://forums.databricks.com/","dbfsS3Host":"https://databricks-prod-storage-sydney.s3.amazonaws.com","enableThirdPartyApplicationsUI":false,"enableClusterAcls":false,"notebookRevisionVisibilityHorizon":0,"enableTableHandler":true,"isAdmin":true,"enableLargeResultDownload":false,"nameAndEmail":"Raazesh Sainudiin (r.sainudiin@math.canterbury.ac.nz)","enablePresentationTimerConfig":true,"enableFullTextSearch":true,"enableElasticSparkUI":true,"clusters":true,"hideOffHeapCache":false,"applications":false,"useStaticGuide":false,"fileStoreBase":"FileStore","configurableSparkOptionsSpec":[{"keyPattern":"spark\\.kryo(\\.[^\\.]+)+","valuePattern":".*","keyPatternDisplay":"spark.kryo.*","valuePatternDisplay":"*","description":"Configuration options for Kryo serialization"},{"keyPattern":"spark\\.io\\.compression\\.codec","valuePattern":"(lzf|snappy|org\\.apache\\.spark\\.io\\.LZFCompressionCodec|org\\.apache\\.spark\\.io\\.SnappyCompressionCodec)","keyPatternDisplay":"spark.io.compression.codec","valuePatternDisplay":"snappy|lzf","description":"The codec used to compress internal data such as RDD partitions, broadcast variables and shuffle outputs."},{"keyPattern":"spark\\.serializer","valuePattern":"(org\\.apache\\.spark\\.serializer\\.JavaSerializer|org\\.apache\\.spark\\.serializer\\.KryoSerializer)","keyPatternDisplay":"spark.serializer","valuePatternDisplay":"org.apache.spark.serializer.JavaSerializer|org.apache.spark.serializer.KryoSerializer","description":"Class to use for serializing objects that will be sent over the network or need to be cached in serialized form."},{"keyPattern":"spark\\.rdd\\.compress","valuePattern":"(true|false)","keyPatternDisplay":"spark.rdd.compress","valuePatternDisplay":"true|false","description":"Whether to compress serialized RDD partitions (e.g. for StorageLevel.MEMORY_ONLY_SER). Can save substantial space at the cost of some extra CPU time."},{"keyPattern":"spark\\.speculation","valuePattern":"(true|false)","keyPatternDisplay":"spark.speculation","valuePatternDisplay":"true|false","description":"Whether to use speculation (recommended off for streaming)"},{"keyPattern":"spark\\.es(\\.[^\\.]+)+","valuePattern":".*","keyPatternDisplay":"spark.es.*","valuePatternDisplay":"*","description":"Configuration options for ElasticSearch"},{"keyPattern":"es(\\.([^\\.]+))+","valuePattern":".*","keyPatternDisplay":"es.*","valuePatternDisplay":"*","description":"Configuration options for ElasticSearch"},{"keyPattern":"spark\\.(storage|shuffle)\\.memoryFraction","valuePattern":"0?\\.0*([1-9])([0-9])*","keyPatternDisplay":"spark.(storage|shuffle).memoryFraction","valuePatternDisplay":"(0.0,1.0)","description":"Fraction of Java heap to use for Spark's shuffle or storage"},{"keyPattern":"spark\\.streaming\\.backpressure\\.enabled","valuePattern":"(true|false)","keyPatternDisplay":"spark.streaming.backpressure.enabled","valuePatternDisplay":"true|false","description":"Enables or disables Spark Streaming's internal backpressure mechanism (since 1.5). This enables the Spark Streaming to control the receiving rate based on the current batch scheduling delays and processing times so that the system receives only as fast as the system can process. Internally, this dynamically sets the maximum receiving rate of receivers. This rate is upper bounded by the values `spark.streaming.receiver.maxRate` and `spark.streaming.kafka.maxRatePerPartition` if they are set."},{"keyPattern":"spark\\.streaming\\.receiver\\.maxRate","valuePattern":"^([0-9]{1,})$","keyPatternDisplay":"spark.streaming.receiver.maxRate","valuePatternDisplay":"numeric","description":"Maximum rate (number of records per second) at which each receiver will receive data. Effectively, each stream will consume at most this number of records per second. Setting this configuration to 0 or a negative number will put no limit on the rate. See the deployment guide in the Spark Streaming programing guide for mode details."},{"keyPattern":"spark\\.streaming\\.kafka\\.maxRatePerPartition","valuePattern":"^([0-9]{1,})$","keyPatternDisplay":"spark.streaming.kafka.maxRatePerPartition","valuePatternDisplay":"numeric","description":"Maximum rate (number of records per second) at which data will be read from each Kafka partition when using the Kafka direct stream API introduced in Spark 1.3. See the Kafka Integration guide for more details."},{"keyPattern":"spark\\.streaming\\.kafka\\.maxRetries","valuePattern":"^([0-9]{1,})$","keyPatternDisplay":"spark.streaming.kafka.maxRetries","valuePatternDisplay":"numeric","description":"Maximum number of consecutive retries the driver will make in order to find the latest offsets on the leader of each partition (a default value of 1 means that the driver will make a maximum of 2 attempts). Only applies to the Kafka direct stream API introduced in Spark 1.3."},{"keyPattern":"spark\\.streaming\\.ui\\.retainedBatches","valuePattern":"^([0-9]{1,})$","keyPatternDisplay":"spark.streaming.ui.retainedBatches","valuePatternDisplay":"numeric","description":"How many batches the Spark Streaming UI and status APIs remember before garbage collecting."}],"enableReactNotebookComments":true,"enableResetPassword":true,"enableJobsSparkUpgrade":true,"sparkVersions":[{"key":"1.3.x-ubuntu15.10","displayName":"Spark 1.3.0","packageLabel":"spark-1.3-jenkins-ip-10-30-9-162-U0c2673ac85-Sa2ee4664b2-2016-02-09-02:05:59.455061","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"1.4.x-ubuntu15.10","displayName":"Spark 1.4.1","packageLabel":"spark-1.4-jenkins-ip-10-30-9-162-U0c2673ac85-S33a1e4b9c6-2016-02-09-02:05:59.455061","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"1.5.x-ubuntu15.10","displayName":"Spark 1.5.2","packageLabel":"spark-1.5-jenkins-ip-10-30-9-162-U0c2673ac85-S5917a1044d-2016-02-09-02:05:59.455061","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"1.6.x-ubuntu15.10","displayName":"Spark 1.6.0","packageLabel":"spark-1.6-jenkins-ip-10-30-9-162-U0c2673ac85-Scabba801f3-2016-02-09-02:05:59.455061","upgradable":true,"deprecated":false,"customerVisible":true},{"key":"master","displayName":"Spark master (dev)","packageLabel":"","upgradable":true,"deprecated":false,"customerVisible":false}],"enableRestrictedClusterCreation":false,"enableFeedback":false,"defaultNumWorkers":8,"serverContinuationTimeoutMillis":10000,"driverStderrFilePrefix":"stderr","driverStdoutFilePrefix":"stdout","enableSparkDocsSearch":true,"prefetchSidebarNodes":true,"sparkHistoryServerEnabled":true,"sanitizeMarkdownHtml":true,"enableIPythonImportExport":true,"enableNotebookHistoryDiffing":true,"branch":"2.12.3","accountsLimit":-1,"enableNotebookGitBranching":true,"local":false,"displayDefaultContainerMemoryGB":6,"deploymentMode":"production","useSpotForWorkers":false,"enableUserInviteWorkflow":false,"enableStaticNotebooks":true,"dbcGuideURL":"#workspace/databricks_guide/00 Welcome to Databricks","enableCssTransitions":true,"pricingURL":"https://databricks.com/product/pricing","enableClusterAclsConfig":false,"orgId":0,"enableNotebookGitVersioning":true,"files":"files/","enableDriverLogsUI":true,"disableLegacyDashboards":false,"enableWorkspaceAclsConfig":true,"dropzoneMaxFileSize":4096,"enableNewDashboardViews":false,"driverLog4jFilePrefix":"log4j","enableMavenLibraries":true,"displayRowLimit":1000,"defaultSparkVersion":{"key":"1.5.x-ubuntu15.10","displayName":"Spark 1.5.2","packageLabel":"spark-1.5-jenkins-ip-10-30-9-162-U0c2673ac85-S5917a1044d-2016-02-09-02:05:59.455061","upgradable":true,"deprecated":false,"customerVisible":true},"clusterPublisherRootId":5,"enableLatestJobRunResultPermalink":true,"disallowAddingAdmins":false,"enableSparkConfUI":true,"enableOrgSwitcherUI":false,"clustersLimit":-1,"enableJdbcImport":true,"logfiles":"logfiles/","enableWebappSharding":false,"enableClusterDeltaUpdates":true,"csrfToken":"3dde4939-9fec-41a8-bc90-741d1aa44ca4","useFixedStaticNotebookVersionForDevelopment":false,"enableBasicReactDialogBoxes":true,"requireEmailUserName":true,"enableDashboardViews":false,"dbcFeedbackURL":"http://feedback.databricks.com/forums/263785-product-feedback","enableWorkspaceAclService":true,"someName":"Raazesh Sainudiin","enableWorkspaceAcls":true,"gitHash":"0c2673ac858e227cad536fdb45d140aeded238db","userFullname":"Raazesh Sainudiin","enableClusterCreatePage":false,"enableImportFromUrl":true,"enableMiniClusters":false,"enableWebSocketDeltaUpdates":true,"enableDebugUI":false,"showHiddenSparkVersions":false,"allowNonAdminUsers":true,"userId":100005,"dbcSupportURL":"","staticNotebookResourceUrl":"https://databricks-prod-cloudfront.cloud.databricks.com/static/201602081754420800-0c2673ac858e227cad536fdb45d140aeded238db/","enableSparkPackages":true,"enableHybridClusterType":false,"enableNotebookHistoryUI":true,"availableWorkspaces":[{"name":"Workspace 0","orgId":0}],"enableFolderHtmlExport":true,"enableSparkVersionsUI":true,"databricksGuideStaticUrl":"","enableHybridClusters":true,"notebookLoadingBackground":"#fff","enableNewJobRunDetailsPage":true,"enableDashboardExport":true,"user":"r.sainudiin@math.canterbury.ac.nz","enableServerAutoComplete":true,"enableStaticHtmlImport":true,"defaultMemoryPerContainerMB":6000,"enablePresenceUI":true,"tablesPublisherRootId":7,"enableNewInputWidgetUI":false,"accounts":true,"enableNewProgressReportUI":true,"defaultCoresPerContainer":4};</script> <script>var __DATABRICKS_NOTEBOOK_MODEL = {"version":"NotebookV1","origId":44147,"name":"017_LAlgIntro","language":"scala","commands":[{"version":"CommandV1","origId":44156,"guid":"6809c529-db8b-4d11-baa5-772832e226de","subtype":"command","commandType":"auto","position":0.125,"command":"%md\n\n# [Scalable Data Science](http://www.math.canterbury.ac.nz/~r.sainudiin/courses/ScalableDataScience/)\n\n\n### prepared by [Raazesh Sainudiin](https://nz.linkedin.com/in/raazesh-sainudiin-45955845) and [Sivanand Sivaram](https://www.linkedin.com/in/sivanand)\n\n*supported by* [](https://databricks.com/)\nand \n[](https://www.awseducate.com/microsite/CommunitiesEngageHome)","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"875a8879-6915-4182-ad95-5c97aa545680"},{"version":"CommandV1","origId":129727,"guid":"cd08a1f5-4a74-4976-80a4-e0b8cf67e256","subtype":"command","commandType":"auto","position":0.5,"command":"%md\nThe [html source url](https://raw.githubusercontent.com/raazesh-sainudiin/scalable-data-science/master/db/week5/09_LinearAlgebraIntro/017_LAlgIntro.html) of this databricks notebook and its recorded Uji :\n\n[](https://www.youtube.com/v/y6F-e6m1m2s?rel=0&autoplay=1&modestbranding=1&start=0&end=2634)\n","commandVersion":0,"state":"error","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"a8d45ed1-c3d9-4362-9bb7-cdf8b84beac1"},{"version":"CommandV1","origId":76298,"guid":"fc25bdf8-90ad-4a61-8b27-7874a831895d","subtype":"command","commandType":"auto","position":0.875,"command":"%md\n## Linear Algebra Review / re-Introduction\n### by Ameet Talwalkar in BerkeleyX: CS190.1x Scalable Machine Learning\n\nThis is a `breeze`'y `scala`rific break-down of:\n* Ameet's Linear Algebra Review in CS190.1x Scalable Machine Learning Course that is archived in edX from 2015 and\n* **Home Work:** read this! [https://github.com/scalanlp/breeze/wiki/Quickstart](https://github.com/scalanlp/breeze/wiki/Quickstart)\n\nUsing the above resources we'll provide a review of basic linear algebra concepts that will recur throughout the course. These concepts include:\n\n1. Matrices\n* Vectors\n* Arithmetic operations with vectors and matrices\n\nWe will see the accompanying Scala computations in the local or non-distributed setting.","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"bc9ba8f1-3dbb-48ba-abd5-1d4029494949"},{"version":"CommandV1","origId":79456,"guid":"5f6654aa-8e9f-4412-839c-75baf59c5043","subtype":"command","commandType":"auto","position":0.8828125,"command":"%md\nLet's get a quick visual geometric interpretation for vectors, matrices and matrix-vector multiplications from the first interactive visual-cognitive aid at:\n * [http://setosa.io/ev/eigenvectors-and-eigenvalues/](http://setosa.io/ev/eigenvectors-and-eigenvalues/) just focus on geometric interpretation of vectors and matrices in Cartesian coordinates.\n ","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"0cc8d80a-7c73-4df9-b597-9064f22c94e2"},{"version":"CommandV1","origId":44160,"guid":"9e6daf3f-e27a-49db-88e6-af13b94bd695","subtype":"command","commandType":"auto","position":0.890625,"command":"%md\n#### Matrix by Ameet Talwalkar in BerkeleyX: CS190.1x Scalable Machine Learning\n**(watch now 0:50)**:\n\n[](https://www.youtube.com/v/mnS0lJncJzw?rel=0&autoplay=1&modestbranding=1&start=10&end=60)\n\n","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"a4ad814a-95b0-42f3-a5ec-adaaf03923d0"},{"version":"CommandV1","origId":76299,"guid":"e039a273-321e-4796-b7f6-0a224bcb22df","subtype":"command","commandType":"auto","position":0.8984375,"command":"%md\nBreeze is a linear algebra package in Scala. First, let us import it as follows:","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"f9272e13-075f-4f6e-acf9-4b1ccc3b2802"},{"version":"CommandV1","origId":44151,"guid":"4d93e9a7-81fd-47e5-89b5-46868caa3d72","subtype":"command","commandType":"auto","position":0.90625,"command":"import breeze.linalg._","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">import breeze.linalg._\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458790939874E12,"submitTime":1.458790806444E12,"finishTime":1.458790939947E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"a713d161-05b3-48b3-bada-ff4fac1b1c2a"},{"version":"CommandV1","origId":76297,"guid":"bfce7111-1e45-4b3d-a15d-e103cee2420a","subtype":"command","commandType":"auto","position":0.9375,"command":"%md\n#### 1. Matrix: creation and element-access\n\nA **matrix** is a two-dimensional array.\n\nLet us denote matrices via bold uppercase letters as follows:\n\nFor instance, the matrix below is denoted with \\\\(\\mathbf{A}\\\\), a capital bold A.\n\n$$\n\\mathbf{A} = \\begin{pmatrix}\na\\_{11} & a\\_{12} & a\\_{13} \\\\\\\\\na\\_{21} & a\\_{22} & a\\_{23} \\\\\\\\\na\\_{31} & a\\_{32} & a\\_{33}\n\\end{pmatrix}\n$$\n\nWe usually put commas between the row and column indexing sub-scripts, to make the possibly multi-digit indices distinguishable as follows:\n\n$$\n\\mathbf{A} = \\begin{pmatrix}\na\\_{1,1} & a\\_{1,2} & a\\_{1,3} \\\\\\\\\na\\_{2,1} & a\\_{2,2} & a\\_{2,3} \\\\\\\\\na\\_{3,1} & a\\_{3,2} & a\\_{3,3}\n\\end{pmatrix}\n$$\n\n* \\\\( \\mathbf{A}\\_{i,j} \\\\) denotes the entry in \\\\(i\\\\)-th row and \\\\(j\\\\)-th column of the matrix \\\\(\\mathbf{A}\\\\).\n* So for instance, \n * the first entry, the top left entry, is denoted by \\\\( \\mathbf{A}\\_{1,1} \\\\).\n * And the entry in the third row and second column is denoted by \\\\( \\mathbf{A}\\_{3,2} \\\\).\n * We say that a matrix with n rows and m columns is an \\\\(n\\\\) by \\\\(m\\\\) matrix and written as \\\\(n \\times m \\\\)\n * The matrix \\\\(\\mathbf{A}\\\\) shown above is a generic \\\\(3 \\times 3\\\\) (pronounced 3-by-3) matrix.\n * And the matrix in Ameet's example in the video above, having 4 rows and 3 columns, is a 4 by 3 matrix.\n * If a matrix \\\\(\\mathbf{A}\\\\) is \\\\(n \\times m \\\\), we write:\n * \\\\(\\mathbf{A} \\in \\mathbb{R}^{n \\times m}\\\\) and say that \\\\(\\mathbf{A}\\\\) is an \\\\(\\mathbb{R}\\\\) to the power of the n times m, \n * where, \\\\(\\mathbb{R}\\\\) here denotes the set of all real numbers in the line given by the open interval: \\\\( (-\\infty,+\\infty)\\\\).","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"2a4d6b38-05ba-4d14-8295-a079f530b341"},{"version":"CommandV1","origId":76392,"guid":"a07ca02d-d463-4eeb-9b62-5e726d11100e","subtype":"command","commandType":"auto","position":0.94140625,"command":"%md\nLet us created a matrix `A` as a `val` (that is immutable) in scala. The matrix we want to create is mathematically notated as follows:\n$$\n\\mathbf{A} = \\begin{pmatrix}\na\\_{1,1} & a\\_{1,2} & a\\_{1,3} \\\\\\\\\na\\_{2,1} & a\\_{2,2} & a\\_{2,3} \n\\end{pmatrix}\n = \n\\begin{pmatrix}\n1 & 2 & 3 \\\\\\\\\n4 & 5 & 6 \n\\end{pmatrix}\n$$","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"e25e3933-480e-4010-b5d9-b35ee1f0046d"},{"version":"CommandV1","origId":46746,"guid":"b80a320f-e104-4973-81b7-d599bd9e7f16","subtype":"command","commandType":"auto","position":0.943359375,"command":"val A = DenseMatrix((1, 2, 3), (4, 5, 6)) // let's create this 2 by 3 matrix","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">A: breeze.linalg.DenseMatrix[Int] = \n1 2 3 \n4 5 6 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":"<div class=\"ansiout\"><console>:32: error: not found: value DenseMatrix\n val A = DenseMatrix((1, 2, 3), (4, 5, 6)) // let's create this 2 by 3 matrix\n ^\n</div>","error":null,"startTime":1.458791049548E12,"submitTime":1.458790916118E12,"finishTime":1.458791049707E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"cf08bf19-14c4-407a-87c0-47cf971dbac9"},{"version":"CommandV1","origId":79469,"guid":"7c09b6fa-00e8-4fe0-87dc-cc5992eae30c","subtype":"command","commandType":"auto","position":0.94384765625,"command":"A.size","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res86: Int = 6\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":"<div class=\"ansiout\"><console>:39: error: Int does not take parameters\n A.size()\n ^\n</div>","error":null,"startTime":1.458791086625E12,"submitTime":1.458790953188E12,"finishTime":1.458791086696E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"9fe8d94a-d9ac-466c-8817-cb2b8d22c179"},{"version":"CommandV1","origId":79470,"guid":"818f3ad0-636b-41e1-8d2f-75ad258fbdee","subtype":"command","commandType":"auto","position":0.944091796875,"command":"A.rows // number of rows","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res87: Int = 2\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":"<div class=\"ansiout\"><console>:39: error: Int does not take parameters\n A.rows()\n ^\n</div>","error":null,"startTime":1.458791099833E12,"submitTime":1.458790966409E12,"finishTime":1.45879109994E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"acb46f2e-0e8d-4aeb-981a-368efc11d7d5"},{"version":"CommandV1","origId":79471,"guid":"17f08539-0311-4319-a0c9-a44fdffc6c08","subtype":"command","commandType":"auto","position":0.9442138671875,"command":"A.size / A.rows // num of columns","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res88: Int = 3\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458791105774E12,"submitTime":1.458790972339E12,"finishTime":1.458791105848E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"dce85d93-4496-4d1c-b96d-9ff0bfcbd6ae"},{"version":"CommandV1","origId":76393,"guid":"e804df5f-e61a-4a06-b133-229035ee03b6","subtype":"command","commandType":"auto","position":0.9443359375,"command":"%md\nNow, let's access the element \\\\(a_{1,1}\\\\), i.e., the element from the first row and first column of \\\\(\\mathbf{A}\\\\), which in our `val A` matrix is the integer of type `Int` equalling `1`.","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"281fbc51-b9c3-46e2-9dcd-1c2483e45cec"},{"version":"CommandV1","origId":46764,"guid":"60fba783-fc92-47fb-8959-e9eae09af872","subtype":"command","commandType":"auto","position":0.9453125,"command":"A(0, 0) // Remember elements are indexed by zero in scala","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res89: Int = 1\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458791128272E12,"submitTime":1.458790994834E12,"finishTime":1.458791128352E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"bb8e4aa2-c365-4ee4-820b-957c75fca42c"},{"version":"CommandV1","origId":76394,"guid":"6f4efe9d-b34b-4268-b76d-9629dfd47828","subtype":"command","commandType":"auto","position":0.94580078125,"command":"%md\n**Gotcha:** indices in breeze matrices start at 0 as in numpy of python and not at 1 as in MATLAB!","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"4ef0e1a6-8ae7-45cb-8fd7-6a5f4db5da1c"},{"version":"CommandV1","origId":76459,"guid":"7dd51969-9a0c-46cc-895f-97034c5d255d","subtype":"command","commandType":"auto","position":0.9462890625,"command":"%md\nOf course if you assign the same dense matrix to a mutable `var` `B` then its entries can be modified as follows:","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"eada2949-43fd-4bba-ab93-535efdcc7f93"},{"version":"CommandV1","origId":76457,"guid":"bdda08ad-97c0-4fea-845e-b1f7e34dbddf","subtype":"command","commandType":"auto","position":0.94677734375,"command":"var B = DenseMatrix((1, 2, 3), (4, 5, 6))","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">B: breeze.linalg.DenseMatrix[Int] = \n1 2 3 \n4 5 6 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458791149687E12,"submitTime":1.458791016262E12,"finishTime":1.458791149776E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"cab1801e-c2bb-43c6-a744-79c31a2635ce"},{"version":"CommandV1","origId":76458,"guid":"d35917b2-f450-427f-b2e4-6c17edf50e7c","subtype":"command","commandType":"auto","position":0.947265625,"command":"B(0,0)=999; B(1,1)=969; B(0,2)=666\nB","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res90: breeze.linalg.DenseMatrix[Int] = \n999 2 666 \n4 969 6 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458791155874E12,"submitTime":1.458791022447E12,"finishTime":1.458791155988E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"dbc61468-13e2-4b50-b793-df3c29362326"},{"version":"CommandV1","origId":44398,"guid":"a785a146-b8a3-481b-b2e5-d743b1195c8b","subtype":"command","commandType":"auto","position":0.953125,"command":"\n%md\n#### Vector\n**(watch now 0:31)**:\n\n[](https://www.youtube.com/v/mnS0lJncJzw?rel=0&autoplay=1&modestbranding=1&start=62&end=93)\n","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"25402c4f-a89f-457a-9517-05a06a68c4eb"},{"version":"CommandV1","origId":76562,"guid":"f1ff8b4e-0576-4812-b8e3-a5402cc54945","subtype":"command","commandType":"auto","position":0.95703125,"command":"%md\n* A vector is a matrix with many rows and one column.\n* We'll denote a vector by bold lowercase letters:\n $$\\mathbf{a} = \\begin{pmatrix} 3.3 \\\\\\\\ 1.0 \\\\\\\\ 6.3 \\\\\\\\ 3.6 \\end{pmatrix}$$\n \n So, the vector above is denoted by \\\\(\\mathbf{a}\\\\), the lowercase, bold a.\n* \\\\(a_i\\\\) denotes the i-th entry of a vector. So for instance:\n * \\\\(a_2\\\\) denotes the second entry of the vector and it is 1.0 for our vector.\n* If a vector is m-dimensional, then we say that \\\\(\\mathbf{a}\\\\) is in \\\\(\\mathbb{R}^m\\\\) and write \\\\(\\mathbf{a} \\in \\mathbb{R}^m\\\\).\n * So our \\\\(\\mathbf{a} \\in \\mathbb{R}^4\\\\).","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"b54bb19b-9138-4c8c-b295-504ce323fb6a"},{"version":"CommandV1","origId":46750,"guid":"81817829-fedb-40f7-a6f6-3178dc5649d3","subtype":"command","commandType":"auto","position":0.9609375,"command":"val a = DenseVector(3.3, 1.0, 6.3, 3.6) // these are row vectors","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">a: breeze.linalg.DenseVector[Double] = DenseVector(3.3, 1.0, 6.3, 3.6)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":"<div class=\"ansiout\"><console>:32: error: not found: value DenseVector\n val a = DenseVector(3.3, 1.0, 6.3, 3.6)\n ^\n</div>","error":null,"startTime":1.458791268715E12,"submitTime":1.458791135276E12,"finishTime":1.458791268815E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"eec07675-c9ee-4d29-becb-c51f10d6a6d2"},{"version":"CommandV1","origId":79478,"guid":"a657bef0-92b8-47c1-b20c-a32553b823b3","subtype":"command","commandType":"auto","position":0.962890625,"command":"a.size // a is a column vector of size 4","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res91: Int = 4\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458791272768E12,"submitTime":1.458791139326E12,"finishTime":1.458791272836E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"d6d32c75-3042-4ffc-b6cb-117f74ee8d88"},{"version":"CommandV1","origId":46767,"guid":"8610df62-db99-4a2d-b9de-35e673968981","subtype":"command","commandType":"auto","position":0.96484375,"command":"a(1) // the second element of a is indexed by 1 as the first element is indexed by 0","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res92: Double = 1.0\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458791275892E12,"submitTime":1.45879114245E12,"finishTime":1.45879127601E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"e334adab-7dfd-4470-b6df-b9af100a7e78"},{"version":"CommandV1","origId":76677,"guid":"9f5bd6e3-ca15-4984-89f6-2e2e1e39096f","subtype":"command","commandType":"auto","position":0.9649658203125,"command":"val a = DenseVector[Double](5, 4, -1) // this makes a vector of Doubles from input Int","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">a: breeze.linalg.DenseVector[Double] = DenseVector(5.0, 4.0, -1.0)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458791293152E12,"submitTime":1.458791159695E12,"finishTime":1.458791293265E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"0a9f6afb-8a37-4229-a127-5698c4dfdbec"},{"version":"CommandV1","origId":76678,"guid":"fd128f2e-80cc-4e7d-abda-a47b19071547","subtype":"command","commandType":"auto","position":0.96502685546875,"command":"val a = DenseVector(5.0, 4.0, -1.0) // this makes a vector of Doubles from type inference . NOTE \"5.0\" is needed not jsy \"5.\"","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">a: breeze.linalg.DenseVector[Double] = DenseVector(5.0, 4.0, -1.0)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458791326959E12,"submitTime":1.458791193482E12,"finishTime":1.458791327091E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"6b6ff512-7a19-4cf9-8940-ac7707130484"},{"version":"CommandV1","origId":76676,"guid":"a0aa4144-3fc3-41fc-9615-8277cdc46c00","subtype":"command","commandType":"auto","position":0.965087890625,"command":"val x = DenseVector.zeros[Double](5) // this will output x: breeze.linalg.DenseVector[Double] = DenseVector(0.0, 0.0, 0.0, 0.0, 0.0)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">x: breeze.linalg.DenseVector[Double] = DenseVector(0.0, 0.0, 0.0, 0.0, 0.0)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458791336016E12,"submitTime":1.458791202556E12,"finishTime":1.458791336125E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"e0b65539-9582-4519-8560-ec196af7b2cf"},{"version":"CommandV1","origId":46754,"guid":"12bfe263-7b41-4cfa-8e5d-89a298d48b25","subtype":"command","commandType":"auto","position":0.96533203125,"command":"%md\n#### Transpose\n**(watch now 1:02)**:\n\n[](https://www.youtube.com/v/mnS0lJncJzw?rel=0&autoplay=1&modestbranding=1&start=95&end=157)\n","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"f722d0c5-8663-4aca-a93c-f4939125bb08"},{"version":"CommandV1","origId":68517,"guid":"903a6fbd-4a57-4bf1-a697-8fe8471b7bcf","subtype":"command","commandType":"auto","position":0.9658203125,"command":"%md\nSuggested Home Work for the linear-algebraically rusty (LiAlRusty): watch again and take notes.","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"96c87eb9-a948-4939-9090-88f3b6c53678"},{"version":"CommandV1","origId":79457,"guid":"574f65f4-3a46-4ef4-a61a-33eab1978015","subtype":"command","commandType":"auto","position":0.966064453125,"command":"val A = DenseMatrix((1, 4), (6, 1), (3, 5)) // let's create this 2 by 3 matrix","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">A: breeze.linalg.DenseMatrix[Int] = \n1 4 \n6 1 \n3 5 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458791433446E12,"submitTime":1.458791300009E12,"finishTime":1.458791433554E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"be6a92df-e980-46f0-b70f-d9d7df0868f3"},{"version":"CommandV1","origId":46781,"guid":"3362ac35-947f-46e1-8dad-a82591b54637","subtype":"command","commandType":"auto","position":0.96630859375,"command":"A.t // transpose of A","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res93: breeze.linalg.DenseMatrix[Int] = \n1 6 3 \n4 1 5 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458791443567E12,"submitTime":1.458791310126E12,"finishTime":1.458791443679E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"2b8d057e-0587-4b7e-a87e-f9259f4f8982"},{"version":"CommandV1","origId":79458,"guid":"717fba79-9599-4c74-bde4-caa84898972e","subtype":"command","commandType":"auto","position":0.966552734375,"command":"val a = DenseVector(3.0, 4.0, 1.0)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">a: breeze.linalg.DenseVector[Double] = DenseVector(3.0, 4.0, 1.0)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458791451664E12,"submitTime":1.458791318215E12,"finishTime":1.458791451802E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"f5fabe5a-e3c7-4526-b0c4-5e8c0409079c"},{"version":"CommandV1","origId":46752,"guid":"2775743e-7b78-4506-948e-17201c551177","subtype":"command","commandType":"auto","position":0.966796875,"command":"a.t","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res94: breeze.linalg.Transpose[breeze.linalg.DenseVector[Double]] = Transpose(DenseVector(3.0, 4.0, 1.0))\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458791455394E12,"submitTime":1.45879132175E12,"finishTime":1.458791455516E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"fcc3270d-2347-4e63-8442-4dfffe5252f7"},{"version":"CommandV1","origId":46783,"guid":"5a4c2a33-ba59-421f-abb6-c38c3a13f0f5","subtype":"command","commandType":"auto","position":0.9677734375,"command":"%md\n#### Addition and Subtraction\n**(watch now 0:59)**:\n\n[](https://www.youtube.com/v/mnS0lJncJzw?rel=0&autoplay=1&modestbranding=1&start=157&end=216)\n","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"49eaa412-289e-4a3e-aa41-b64a8e6a0039"},{"version":"CommandV1","origId":76563,"guid":"5869ad3f-8047-40b8-94ad-33e4d91c0ec4","subtype":"command","commandType":"auto","position":0.968017578125,"command":"%md\nSuggested Home Work for LiAlRusty: watch again and take notes.\n\n **Pop Quiz:**\n \n * what is a natural geometric interpretation of vector addition, subtraction, matric addition and subtraction?","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"b4458510-be9d-4240-addb-d29817f4aaf7"},{"version":"CommandV1","origId":79472,"guid":"cdf41a48-7554-402d-9ce6-666a57a9b8f5","subtype":"command","commandType":"auto","position":0.96807861328125,"command":"val A = DenseMatrix((1, 4), (6, 1), (3, 5)) ","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">A: breeze.linalg.DenseMatrix[Int] = \n1 4 \n6 1 \n3 5 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458791793195E12,"submitTime":1.458791659721E12,"finishTime":1.458791793304E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"3fb639d4-a16c-46f7-afc0-bf8de1592d4d"},{"version":"CommandV1","origId":46788,"guid":"c8daec1d-237f-4224-87ed-d414ef5e0e8d","subtype":"command","commandType":"auto","position":0.96826171875,"command":"val B = -A ","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">B: breeze.linalg.DenseMatrix[Int] = \n-1 -4 \n-6 -1 \n-3 -5 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":"<div class=\"ansiout\"><console>:39: error: wrong number of type parameters for method apply: [R, V](rows: R*)(implicit rl: breeze.linalg.support.LiteralRow[R,V], implicit man: scala.reflect.ClassTag[V], implicit zero: breeze.storage.Zero[V])breeze.linalg.DenseMatrix[V] in trait MatrixConstructors\n val B = DenseMatrix[Double]((-1, -4, -2), (4, 2, 9))\n ^\n</div>","error":null,"startTime":1.458791796987E12,"submitTime":1.458791663505E12,"finishTime":1.458791797246E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"e9971205-2fdc-4f24-82e1-9cad34fbfcb4"},{"version":"CommandV1","origId":79461,"guid":"e8332423-e509-459e-a844-c2bddbb65fd2","subtype":"command","commandType":"auto","position":0.9683837890625,"command":"A + B // should be A-A=0","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res95: breeze.linalg.DenseMatrix[Int] = \n0 0 \n0 0 \n0 0 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458791800869E12,"submitTime":1.458791667397E12,"finishTime":1.458791801092E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"fd824eae-f73d-4ee1-91a2-88032df9d93d"},{"version":"CommandV1","origId":79460,"guid":"8a85f771-5daf-49d5-acd3-586ef9fd720e","subtype":"command","commandType":"auto","position":0.96844482421875,"command":"A - B // should be A+A=2A","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res96: breeze.linalg.DenseMatrix[Int] = \n2 8 \n12 2 \n6 10 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458791803703E12,"submitTime":1.458791670245E12,"finishTime":1.45879180393E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"0b0580b8-6cfb-4b26-aeca-300bb0327af4"},{"version":"CommandV1","origId":46791,"guid":"1217ad28-be5e-43a7-ac12-ddaf9544da9a","subtype":"command","commandType":"auto","position":0.968505859375,"command":"B - A // should be -A-A=-2A","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res97: breeze.linalg.DenseMatrix[Int] = \n-2 -8 \n-12 -2 \n-6 -10 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":"java.lang.ArrayIndexOutOfBoundsException: 6","error":"<div class=\"ansiout\">\tat breeze.linalg.operators.DenseMatrixOps$$anon$42.apply(DenseMatrixOps.scala:453)\n\tat breeze.linalg.operators.DenseMatrixOps$$anon$42.apply(DenseMatrixOps.scala:439)\n\tat breeze.linalg.operators.DenseMatrixOps$$anon$154.apply(DenseMatrixOps.scala:629)\n\tat breeze.linalg.operators.DenseMatrixOps$$anon$154.apply(DenseMatrixOps.scala:626)\n\tat breeze.linalg.ImmutableNumericOps$class.$minus(NumericOps.scala:55)\n\tat breeze.linalg.DenseMatrix.$minus(DenseMatrix.scala:53)</div>","startTime":1.458791807816E12,"submitTime":1.458791674348E12,"finishTime":1.458791808049E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"d3599d37-87e2-415d-ad7b-1ea5787e37a6"},{"version":"CommandV1","origId":46813,"guid":"2d6ad85f-8520-46f2-bda1-0e827a6c8fca","subtype":"command","commandType":"auto","position":0.9685211181640625,"command":"%md\n### Operators\n\nAll Tensors support a set of operators, similar to those used in Matlab or Numpy. \n\nFor **HOMEWORK** see: [Workspace -> scalable-data-science -> xtraResources -> LinearAlgebra -> LAlgCheatSheet](/#workspace/scalable-data-science/xtraResources/LinearAlgebra/LAlgCheatSheet) for a list of most of the operators and various operations. \n\nSome of the basic ones are reproduced here, to give you an idea.\n\n| Operation | Breeze | Matlab | Numpy |\n|---|---|---|---|\n| Elementwise addition | ``a + b`` | ``a + b`` | ``a + b`` |\n| Elementwise multiplication | ``a :* b`` | ``a .* b`` | ``a * b`` |\n| Elementwise comparison | ``a :< b`` | ``a < b`` (gives matrix of 1/0 instead of true/false)| ``a < b`` |\n| Inplace addition | ``a :+= 1.0`` | ``a += 1`` | ``a += 1`` |\n| Inplace elementwise multiplication | ``a :*= 2.0`` | ``a *= 2`` | ``a *= 2`` |\n| Vector dot product | ``a dot b``,``a.t * b``<sup>?</sup> | ``dot(a,b)`` | ``dot(a,b)`` |\n| Elementwise sum | ``sum(a)``| ``sum(sum(a))`` | ``a.sum()`` |\n| Elementwise max | ``a.max``| ``max(a)`` | ``a.max()`` |\n| Elementwise argmax | ``argmax(a)``| ``argmax(a)`` | ``a.argmax()`` |\n| Ceiling | ``ceil(a)``| ``ceil(a)`` | ``ceil(a)`` |\n| Floor | ``floor(a)``| ``floor(a)`` | ``floor(a)`` |","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"9d6d573e-2ee6-446b-ac4e-ae38da90954f"},{"version":"CommandV1","origId":46809,"guid":"7e00a6a5-9bc3-47aa-9d61-ca78f07e6a1e","subtype":"command","commandType":"auto","position":0.9685287475585938,"command":"%md\n#### Scalar multiplication, Dot Product and Matrix-Vector multiplication\n**(watch now 2:26)**:\n\n[](https://www.youtube.com/v/mnS0lJncJzw?rel=0&autoplay=1&modestbranding=1&start=218&end=377)","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"822dcd6a-cff8-4310-bcf7-eb2884f89d3e"},{"version":"CommandV1","origId":79462,"guid":"9341fa37-b0d3-4eed-b2d5-0ec50c1bcfe7","subtype":"command","commandType":"auto","position":0.9685325622558594,"command":"%md\nSuggested Home Work for LiAlRusty: watch again and take notes.\n\n **Pop Quiz:**\n \n * what is a natural geometric interpretation of scalar multiplication of a vector or a matrix and what about vector matrix multiplication?\n \n Let's get a quick visual geometric interpretation for vectors, matrices and matrix-vector multiplications from the first interactive visual-cognitive aid at:\n * [http://setosa.io/ev/eigenvectors-and-eigenvalues/](http://setosa.io/ev/eigenvectors-and-eigenvalues/) ","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"e693af5e-1f1b-4bbb-84fe-84e1663d4265"},{"version":"CommandV1","origId":79476,"guid":"5238eb80-39de-4afb-a0a4-96e50c3612e2","subtype":"command","commandType":"auto","position":0.9685344696044922,"command":"val A = DenseMatrix((1, 4), (6, 1), (3, 5)) ","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">A: breeze.linalg.DenseMatrix[Int] = \n1 4 \n6 1 \n3 5 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458792206663E12,"submitTime":1.458792073166E12,"finishTime":1.458792206789E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"8979fc13-68f5-4e24-8c52-36202ef28058"},{"version":"CommandV1","origId":46808,"guid":"0cae6f78-b076-4670-9afb-d94ef13b67e5","subtype":"command","commandType":"auto","position":0.968536376953125,"command":"5 * A","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res99: breeze.linalg.DenseMatrix[Int] = \n5 20 \n30 5 \n15 25 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":"<div class=\"ansiout\"><console>:39: error: could not find implicit value for parameter op: breeze.linalg.operators.OpMulMatrix.Impl2[Double,breeze.linalg.DenseMatrix[Int],That]\n 5.0 * A\n ^\n</div>","error":null,"startTime":1.458792230428E12,"submitTime":1.45879209691E12,"finishTime":1.458792230782E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"6d21553d-5efb-4249-b562-1ad8b38e8cf4"},{"version":"CommandV1","origId":76564,"guid":"96793587-ef3d-457a-8824-85b9e57649d6","subtype":"command","commandType":"auto","position":0.96856689453125,"command":"A * 5","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res100: breeze.linalg.DenseMatrix[Int] = \n5 20 \n30 5 \n15 25 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":"<div class=\"ansiout\"><console>:39: error: could not find implicit value for parameter op: breeze.linalg.operators.OpMulMatrix.Impl2[breeze.linalg.DenseMatrix[Int],Double,That]\n A * 5.0\n ^\n</div>","error":null,"startTime":1.458792234459E12,"submitTime":1.458792100964E12,"finishTime":1.458792234645E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"e997ca76-25b1-4588-8b5d-a3782544568b"},{"version":"CommandV1","origId":46814,"guid":"e2e5c0f9-00b1-4e3a-8155-734eb53b9fae","subtype":"command","commandType":"auto","position":0.968597412109375,"command":"%md\n#### Dot product","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"0b39ddb6-8291-464b-b8df-14dd8ede52cd"},{"version":"CommandV1","origId":79463,"guid":"1d4061c4-1299-4528-97d2-a4425f7e7983","subtype":"command","commandType":"auto","position":0.9686126708984375,"command":"val A = DenseMatrix((1, 4), (6, 1), (3, 5)) ","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">A: breeze.linalg.DenseMatrix[Int] = \n1 4 \n6 1 \n3 5 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458792260043E12,"submitTime":1.458792126562E12,"finishTime":1.458792260157E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"3b9b5c88-3437-4eed-8525-8f1aeea9237c"},{"version":"CommandV1","origId":79464,"guid":"bce8f7fe-db39-4803-944a-07e909140230","subtype":"command","commandType":"auto","position":0.9686203002929688,"command":"val B = DenseMatrix((3, 1), (2, 2), (1, 3)) ","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">B: breeze.linalg.DenseMatrix[Int] = \n3 1 \n2 2 \n1 3 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458792264195E12,"submitTime":1.458792130702E12,"finishTime":1.458792264287E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"0a6cd16d-4428-40cd-aea3-58a4dffc098e"},{"version":"CommandV1","origId":46802,"guid":"effcc188-cfa1-40ce-be5c-e881714a69ac","subtype":"command","commandType":"auto","position":0.9686279296875,"command":"A :* B // element-wise multiplication","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res101: breeze.linalg.DenseMatrix[Int] = \n3 4 \n12 2 \n3 15 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":"java.lang.IllegalArgumentException: requirement failed","error":"<div class=\"ansiout\">\tat scala.Predef$.require(Predef.scala:221)\n\tat breeze.linalg.operators.DenseMatrixMultOps$$anon$175.apply(DenseMatrixOps.scala:809)\n\tat breeze.linalg.operators.DenseMatrixMultOps$$anon$175.apply(DenseMatrixOps.scala:785)\n\tat breeze.linalg.ImmutableNumericOps$class.$times(NumericOps.scala:135)\n\tat breeze.linalg.DenseMatrix.$times(DenseMatrix.scala:53)</div>","startTime":1.458792268504E12,"submitTime":1.458792135019E12,"finishTime":1.458792268789E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"15cb6b91-ae93-4bb4-9415-8116fee77021"},{"version":"CommandV1","origId":46815,"guid":"bfcdb90a-a2e2-4877-97ef-bae786fb1617","subtype":"command","commandType":"auto","position":0.96868896484375,"command":"%md\n#### Matrix Vector multiplication","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"4225c5cf-1792-4025-ac31-1c202c87c4c0"},{"version":"CommandV1","origId":79466,"guid":"1d076d3e-cb95-4f65-986e-73673cf30560","subtype":"command","commandType":"auto","position":0.9687042236328125,"command":"val A = DenseMatrix((1, 4), (3, 1)) ","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">A: breeze.linalg.DenseMatrix[Int] = \n1 4 \n3 1 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458792286213E12,"submitTime":1.458792152718E12,"finishTime":1.458792286312E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"e8e8306e-890e-4d67-9c52-92f49a68d968"},{"version":"CommandV1","origId":79467,"guid":"82510cd3-9b71-47f7-8359-baa22a69bd8f","subtype":"command","commandType":"auto","position":0.9687118530273438,"command":"val a = DenseVector(1, -1) // is a column vector","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">a: breeze.linalg.DenseVector[Int] = DenseVector(1, -1)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458792300724E12,"submitTime":1.458792167228E12,"finishTime":1.458792300844E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"22823f47-e786-48b6-82fb-2faae22e5cb5"},{"version":"CommandV1","origId":79477,"guid":"82a1b846-cd93-4566-84bf-34c5e9727ff5","subtype":"command","commandType":"auto","position":0.9687156677246094,"command":"a.size // a is a column vector of size 2","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res102: Int = 2\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.45879230993E12,"submitTime":1.45879217613E12,"finishTime":1.458792310002E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"1d4e0206-8b9e-4cb0-a07e-3c9b13cf6d6d"},{"version":"CommandV1","origId":46816,"guid":"262f2429-71fd-4ebb-b8c3-b77e610fe02f","subtype":"command","commandType":"auto","position":0.968719482421875,"command":"A * a","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res103: breeze.linalg.DenseVector[Int] = DenseVector(-3, 2)\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":"java.lang.IllegalArgumentException: requirement failed","error":"<div class=\"ansiout\">\tat scala.Predef$.require(Predef.scala:221)\n\tat breeze.linalg.operators.DenseMatrixMultOps$$anon$175.apply(DenseMatrixOps.scala:809)\n\tat breeze.linalg.operators.DenseMatrixMultOps$$anon$175.apply(DenseMatrixOps.scala:785)\n\tat breeze.linalg.operators.DenseVector_GenericOps$$anon$314.apply(DenseVectorOps.scala:698)\n\tat breeze.linalg.operators.DenseVector_GenericOps$$anon$314.apply(DenseVectorOps.scala:694)\n\tat breeze.linalg.ImmutableNumericOps$class.$times(NumericOps.scala:135)\n\tat breeze.linalg.DenseMatrix.$times(DenseMatrix.scala:53)</div>","startTime":1.458792312875E12,"submitTime":1.458792179236E12,"finishTime":1.458792313749E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"8fbb9eb6-a225-40d2-a613-1fa1ae0c6a9a"},{"version":"CommandV1","origId":46817,"guid":"a7903bea-b48f-4e40-bdf8-a5b7afef5893","subtype":"command","commandType":"auto","position":0.9687347412109375,"command":"%md\n#### Matrix-Matrix multiplication\n**(watch now 1:59)**:\n\n[](https://www.youtube.com/v/mnS0lJncJzw?rel=0&autoplay=1&modestbranding=1&start=380&end=499)\n","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"89139422-5bb5-4ac7-93d2-eebcf9c63176"},{"version":"CommandV1","origId":79483,"guid":"19be3507-a07a-4d65-8e6f-a5e3ed74b1e9","subtype":"command","commandType":"auto","position":0.9687385559082031,"command":"val A = DenseMatrix((1,2,3),(1,1,1))","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">A: breeze.linalg.DenseMatrix[Int] = \n1 2 3 \n1 1 1 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458792472489E12,"submitTime":1.458792338989E12,"finishTime":1.458792472586E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"d6b83b75-d712-4c25-ac5a-07d300f997d4"},{"version":"CommandV1","origId":46818,"guid":"1a0e6871-39b5-4dd7-92ad-94ea1bea929e","subtype":"command","commandType":"auto","position":0.9687423706054688,"command":"val B = DenseMatrix((4, 1), (9, 2), (8, 9))","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">B: breeze.linalg.DenseMatrix[Int] = \n4 1 \n9 2 \n8 9 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458792475908E12,"submitTime":1.458792342398E12,"finishTime":1.458792476028E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"d33d53bf-ca28-4496-b778-89a97657914e"},{"version":"CommandV1","origId":79484,"guid":"554dd421-da49-4f5b-a8af-e77b6587a81b","subtype":"command","commandType":"auto","position":0.9687433242797852,"command":"A*B // 4+18+14","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res104: breeze.linalg.DenseMatrix[Int] = \n46 32 \n21 12 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458792483937E12,"submitTime":1.458792350423E12,"finishTime":1.45879248415E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"9f3154f6-7f4b-4b8d-91d5-428241f717a0"},{"version":"CommandV1","origId":79485,"guid":"7b3e9ede-ddf9-4a57-9465-e8386cb546b3","subtype":"command","commandType":"auto","position":0.9687438011169434,"command":"1*4 + 2*9 + 3*8 // checking first entry of A*B","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res105: Int = 46\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.45879249131E12,"submitTime":1.458792357799E12,"finishTime":1.458792491399E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"81802002-b01e-45e2-b068-d5062c31a933"},{"version":"CommandV1","origId":46820,"guid":"ff508b4a-a6cb-45df-8294-d9179d271386","subtype":"command","commandType":"auto","position":0.9687442779541016,"command":"%md\n#### Identity Matrix\n**(watch now 0:53)**:\n\n[](https://www.youtube.com/v/mnS0lJncJzw?rel=0&autoplay=1&modestbranding=1&start=530&end=583)\n","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"65dbfafe-002f-4267-90f1-6ae1ac3df0f8"},{"version":"CommandV1","origId":79486,"guid":"1649b37b-abd2-4250-b980-1c4b2df3cad2","subtype":"command","commandType":"auto","position":0.968745231628418,"command":"val A = DenseMatrix((1,2,3),(4,5,6))","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">A: breeze.linalg.DenseMatrix[Int] = \n1 2 3 \n4 5 6 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458792564083E12,"submitTime":1.45879243056E12,"finishTime":1.458792564241E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"eef9248a-19b4-430a-92c2-388835add223"},{"version":"CommandV1","origId":46819,"guid":"1d62dfb1-a169-4b58-b63d-1da2c6a2601b","subtype":"command","commandType":"auto","position":0.9687461853027344,"command":"A * DenseMatrix.eye[Int](3)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res106: breeze.linalg.DenseMatrix[Int] = \n1 2 3 \n4 5 6 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":"<div class=\"ansiout\"><console>:37: error: ambiguous implicit values:\n both object IntZero in object Zero of type breeze.storage.Zero.IntZero.type\n and object ShortZero in object Zero of type breeze.storage.Zero.ShortZero.type\n match expected type breeze.storage.Zero[V]\n DenseMatrix.eye(2)\n ^\n</div>","error":null,"startTime":1.458792567667E12,"submitTime":1.45879243414E12,"finishTime":1.458792567913E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"e5e2ff04-dfde-4aff-889a-3119fc57284f"},{"version":"CommandV1","origId":79487,"guid":"04c9a950-ddd8-4b56-ab59-eace6047f3cb","subtype":"command","commandType":"auto","position":0.9687471389770508,"command":"DenseMatrix.eye[Int](2) * A","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res107: breeze.linalg.DenseMatrix[Int] = \n1 2 3 \n4 5 6 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458792576078E12,"submitTime":1.458792442572E12,"finishTime":1.45879257634E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"896573ac-ae89-4cfa-b59e-afa22f74053c"},{"version":"CommandV1","origId":46822,"guid":"4e59b376-6c75-4744-9a5d-2e9bbd44e7bd","subtype":"command","commandType":"auto","position":0.9687480926513672,"command":"%md\n#### Inverse\n**(watch now 0:52)**:\n\n[](https://www.youtube.com/v/mnS0lJncJzw?rel=0&autoplay=1&modestbranding=1&start=584&end=636)\n","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"240aeeab-374f-4297-8918-2254910a993f"},{"version":"CommandV1","origId":46823,"guid":"c8e83a58-4bb8-4ba1-928b-2634c79c05e6","subtype":"command","commandType":"auto","position":0.9687490463256836,"command":"val D = DenseMatrix((2.0, 3.0), (4.0, 5.0))\nval Dinv = inv(D)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">D: breeze.linalg.DenseMatrix[Double] = \n2.0 3.0 \n4.0 5.0 \nDinv: breeze.linalg.DenseMatrix[Double] = \n-2.5 1.5 \n2.0 -1.0 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":"<div class=\"ansiout\"><console>:37: error: wrong number of type parameters for method apply: [R, V](rows: R*)(implicit rl: breeze.linalg.support.LiteralRow[R,V], implicit man: scala.reflect.ClassTag[V], implicit zero: breeze.storage.Zero[V])breeze.linalg.DenseMatrix[V] in trait MatrixConstructors\n val D = DenseMatrix[Double]((2.0, 3.0), (4.0, 5.0))\n ^\n</div>","error":null,"startTime":1.458792666142E12,"submitTime":1.458792532617E12,"finishTime":1.458792666349E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"2839e702-017f-446f-b4ad-9fa618e2f5b0"},{"version":"CommandV1","origId":46824,"guid":"2a418ebb-a8df-4a27-9708-7e76c61ba925","subtype":"command","commandType":"auto","position":0.9687495231628418,"command":"D * Dinv","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res108: breeze.linalg.DenseMatrix[Double] = \n1.0 0.0 \n0.0 1.0 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458792677062E12,"submitTime":1.458792543455E12,"finishTime":1.458792677299E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"6065bbe1-6a8e-43d0-84cb-6fa989d72ee3"},{"version":"CommandV1","origId":79492,"guid":"ee4aba3f-3664-4fde-8518-021b969bc920","subtype":"command","commandType":"auto","position":0.9687495827674866,"command":"Dinv * D","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res80: breeze.linalg.DenseMatrix[Double] = \n1.0 0.0 \n0.0 1.0 \n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":null,"error":null,"startTime":1.458781262163E12,"submitTime":1.458781129222E12,"finishTime":1.458781262363E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"568a7720-be38-4475-9d3c-8e8e43ee4d43"},{"version":"CommandV1","origId":46826,"guid":"9db7e01f-77cf-4f2b-a937-1f6e78fd59e2","subtype":"command","commandType":"auto","position":0.9687496423721313,"command":"%md\n#### Eucledian distance / norm\n**(watch now 0:52)**:\n\n[](https://www.youtube.com/v/mnS0lJncJzw?rel=0&autoplay=1&modestbranding=1&start=638&end=682)\n","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"3a36a578-04a9-49dd-b60c-4a74a4ffb559"},{"version":"CommandV1","origId":46825,"guid":"ac7a31d4-8fcc-4f23-a934-cb63dc49f4cf","subtype":"command","commandType":"auto","position":0.9687497615814209,"command":"val b = DenseVector(4, 3)\nnorm(b)","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">b: breeze.linalg.DenseVector[Int] = DenseVector(4, 3)\nres109: Double = 5.0\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":"<div class=\"ansiout\"><console>:38: error: not found: value b\n norm(b)\n ^\n<console>:42: error: not found: value b\nval $ires9 = b\n ^\n<console>:35: error: not found: value b\n b = DenseVector(2, 3)\n ^\n</div>","error":null,"startTime":1.458792747307E12,"submitTime":1.45879261377E12,"finishTime":1.458792747537E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"ab0de3c7-d119-461a-a77c-292978bcbdac"},{"version":"CommandV1","origId":79493,"guid":"76018fed-f42e-47d4-8855-55a22a176ddf","subtype":"command","commandType":"auto","position":0.9687498807907104,"command":"Math.sqrt(4*4 + 3*3) // check","commandVersion":0,"state":"finished","results":{"type":"html","data":"<div class=\"ansiout\">res110: Double = 5.0\n</div>","arguments":{},"addedWidgets":{},"removedWidgets":[]},"errorSummary":"<div class=\"ansiout\"><console>:37: error: value ^ is not a member of Double\n Math.sqrt(4.0^2 + 3.0^2)\n ^\n</div>","error":null,"startTime":1.45879275084E12,"submitTime":1.458792617322E12,"finishTime":1.458792750963E12,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"r.sainudiin@math.canterbury.ac.nz","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"9c8aa2a4-bb42-4c06-8640-8f28cbcf6a7c"},{"version":"CommandV1","origId":44149,"guid":"bc695b53-56eb-42c2-8568-6aa87aa867f9","subtype":"command","commandType":"auto","position":1.0,"command":"%md\n**HOMEWORK:** read this! [https://github.com/scalanlp/breeze/wiki/Quickstart](https://github.com/scalanlp/breeze/wiki/Quickstart)\n\n It is here in markdown'd via wget and pandoc for your convenience.\n\n#### Scala / nlp / breeze / Quickstart\n\nDavid Hall edited this page on 24 Dec 2015\n\n \nBreeze is modeled on Scala, and so if you're familiar with it, you'll be familiar with Breeze. First, import the linear algebra package:\n\n```scala\nscala> import breeze.linalg._\n```\n\nLet's create a vector:\n```scala\nscala> val x = DenseVector.zeros[Double](5)\nx: breeze.linalg.DenseVector[Double] = DenseVector(0.0, 0.0, 0.0, 0.0, 0.0)\n```\n \nHere we make a column vector of zeros of type Double. And there are other ways we could create the vector - such as with a literal `DenseVector(1,2,3)` or with a call to `fill` or `tabulate`. The vector is \"dense\" because it is backed by an `Array[Double]`, but could as well have created a `SparseVector.zeros[Double](5)`, which would not allocate memory for zeros. \n\n **Unlike Scalala, all Vectors are column vectors.** Row vectors are represented as `Transpose[Vector[T]]`.\n\nThe vector object supports accessing and updating data elements by their index in `0` to `x.length-1`. Like Numpy, negative indices are supported, with the semantics that for an index `i < 0` we operate on the i-th element from the end (`x(i) == x(x.length + i)`).\n\n```scala\nscala> x(0)\nDouble = 0.0\n\nscala> x(1) = 2\n\nscala> x\nbreeze.linalg.DenseVector[Double] = DenseVector(0.0, 2.0, 0.0, 0.0, 0.0)\n```\n\nBreeze also supports slicing. **Note that slices using a Range are much, much faster than those with an arbitrary sequence.**\n\n```scala\nscala> x(3 to 4) := .5\nbreeze.linalg.DenseVector[Double] = DenseVector(0.5, 0.5)\n\nscala> x\nbreeze.linalg.DenseVector[Double] = DenseVector(0.0, 2.0, 0.0, 0.5, 0.5)\n```\n\nThe slice operator constructs a read-through and write-through view of the given elements in the underlying vector. You set its values using the vectorized-set operator `:=`. You could as well have set it to a compatibly sized Vector.\n\n```scala\nscala> x(0 to 1) := DenseVector(.1,.2)\n\nscala> x\nbreeze.linalg.DenseVector[Double] = DenseVector(0.1, 0.2, 0.0, 0.5, 0.5)\n```\n\nSimilarly, a DenseMatrix can be created with a constructor method call, and its elements can be accessed and updated.\n\n```scala\nscala> val m = DenseMatrix.zeros[Int](5,5)\nm: breeze.linalg.DenseMatrix[Int] = \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n```\n\nThe columns of `m` can be accessed as DenseVectors, and the rows as DenseMatrices.\n\n```scala\nscala> (m.rows, m.cols)\n(Int, Int) = (5,5)\n\nscala> m(::,1)\nbreeze.linalg.DenseVector[Int] = DenseVector(0, 0, 0, 0, 0)\n\nscala> m(4,::) := DenseVector(1,2,3,4,5).t // transpose to match row shape\nbreeze.linalg.DenseMatrix[Int] = 1 2 3 4 5 \n\nscala> m\nbreeze.linalg.DenseMatrix[Int] = \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n1 2 3 4 5 \n```\n\nAssignments with incompatible cardinality or a larger numeric type won't compile. \n\n```scala\nscala> m := x\n<console>:13: error: could not find implicit value for parameter op: breeze.linalg.operators.BinaryUpdateOp[breeze.linalg.DenseMatrix[Int],breeze.linalg.DenseVector[Double],breeze.linalg.operators.OpSet]\n m := x\n ^\n```\n\nAssignments with incompatible size will throw an exception:\n\n```scala\nscala> m := DenseMatrix.zeros[Int](3,3)\njava.lang.IllegalArgumentException: requirement failed: Matrices must have same number of row\n```\n\nSub-matrices can be sliced and updated, and literal matrices can be specified using a simple tuple-based syntax. **Unlike Scalala, only range slices are supported, and only the columns (or rows for a transposed matrix) can have a Range step size different from 1.**\n\n```scala\nscala> m(0 to 1, 0 to 1) := DenseMatrix((3,1),(-1,-2)) \nbreeze.linalg.DenseMatrix[Int] = \n3 1 \n-1 -2 \n\nscala> m\nbreeze.linalg.DenseMatrix[Int] = \n3 1 0 0 0 \n-1 -2 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n1 2 3 4 5 \n```\n\n\n\n### Broadcasting\n\nSometimes we want to apply an operation to every row or column of a matrix, as a unit. For instance, you might want to compute the mean of each row, or add a vector to every column. Adapting a matrix so that operations can be applied column-wise or row-wise is called **broadcasting**. Languages like R and numpy automatically and implicitly do broadcasting, meaning they won't stop you if you accidentally add a matrix and a vector. In Breeze, you have to signal your intent using the broadcasting operator `*`. The `*` is meant to evoke \"foreach\" visually. Here are some examples:\n\n```scala\nscala> import breeze.stats.mean\n\nscala> val dm = DenseMatrix((1.0,2.0,3.0),\n (4.0,5.0,6.0))\n\nscala> val res = dm(::, *) + DenseVector(3.0, 4.0)\nbreeze.linalg.DenseMatrix[Double] =\n4.0 5.0 6.0\n8.0 9.0 10.0\n\nscala> res(::, *) := DenseVector(3.0, 4.0)\n\nscala> res\nbreeze.linalg.DenseMatrix[Double] =\n3.0 3.0 3.0\n4.0 4.0 4.0\n\nscala> mean(dm(*, ::))\nbreeze.linalg.DenseVector[Double] = DenseVector(2.0, 5.0)\n```\n\n### breeze.stats.distributions\n\nBreeze also provides a fairly large number of probability distributions. These come with access to probability density function for either discrete or continuous distributions. Many distributions also have methods for giving the mean and the variance.\n\n```scala\nscala> import breeze.stats.distributions._\n\nscala> val poi = new Poisson(3.0);\npoi: breeze.stats.distributions.Poisson = <function1>\n\nscala> val s = poi.sample(5);\ns: IndexedSeq[Int] = Vector(5, 4, 5, 7, 4)\n\nscala> s map { poi.probabilityOf(_) }\nIndexedSeq[Double] = Vector(0.10081881344492458, 0.16803135574154085, 0.10081881344492458, 0.02160403145248382, 0.16803135574154085)\n\nscala> val doublePoi = for(x <- poi) yield x.toDouble // meanAndVariance requires doubles, but Poisson samples over Ints\ndoublePoi: breeze.stats.distributions.Rand[Double] = breeze.stats.distributions.Rand$$anon$11@1b52e04\n\nscala> breeze.stats.meanAndVariance(doublePoi.samples.take(1000));\nbreeze.stats.MeanAndVariance = MeanAndVariance(2.9960000000000067,2.9669509509509533,1000)\n\nscala> (poi.mean,poi.variance)\n(Double, Double) = (3.0,3.0)\n```\n\nNOTE: Below, there is a possibility of confusion for the term `rate` in the family of exponential distributions. Breeze parameterizes the distribution with the mean, but refers to it as the rate.\n\n```scala\n\nscala> val expo = new Exponential(0.5);\nexpo: breeze.stats.distributions.Exponential = Exponential(0.5)\n\nscala> expo.rate\nDouble = 0.5\n```\n\nA characteristic of exponential distributions is its half-life, but we can compute the probability a value falls between any two numbers.\n\n``` scala\n\nscala> expo.probability(0, log(2) * expo.rate)\nDouble = 0.5\n\nscala> expo.probability(0.0, 1.5)\nDouble = 0.950212931632136\n\n```\n\nThis means that approximately 95% of the draws from an exponential distribution fall between 0 and thrice the mean. We could have easily computed this with the cumulative distribution as well\n\n``` scala\n\nscala> 1 - exp(-3.0)\nDouble = 0.950212931632136\n```\n\n``` scala\n\nscala> val samples = expo.sample(2).sorted;\nsamples: IndexedSeq[Double] = Vector(1.1891135726280517, 2.325607782657507)\n\nscala> expo.probability(samples(0), samples(1));\nDouble = 0.08316481553047272\n\nscala> breeze.stats.meanAndVariance(expo.samples.take(10000));\nbreeze.stats.MeanAndVariance = MeanAndVariance(2.029351863973081,4.163267835527843,10000)\n\nscala> (1 / expo.rate, 1 / (expo.rate * expo.rate))\n(Double, Double) = (2.0,4.0)\n```\n\n### breeze.optimize\n\nTODO: document breeze.optimize.minimize, recommend that instead.\n\nBreeze's optimization package includes several convex optimization routines and a simple linear program solver. Convex optimization routines typically take a\n`DiffFunction[T]`, which is a `Function1` extended to have a `gradientAt` method, which returns the gradient at a particular point. Most routines will require\na `breeze.linalg`-enabled type: something like a `Vector` or a `Counter`.\n\nHere's a simple `DiffFunction`: a parabola along each vector's coordinate.\n\n```scala\n\nscala> import breeze.optimize._\n\nscala> val f = new DiffFunction[DenseVector[Double]] {\n | def calculate(x: DenseVector[Double]) = {\n | (norm((x - 3d) :^ 2d,1d),(x * 2d) - 6d);\n | }\n | }\nf: java.lang.Object with breeze.optimize.DiffFunction[breeze.linalg.DenseVector[Double]] = $anon$1@617746b2\n```\n\nNote that this function takes its minimum when all values are 3. (It's just a parabola along each coordinate.)\n\n```scala\nscala> f.valueAt(DenseVector(3,3,3))\nDouble = 0.0\n\nscala> f.gradientAt(DenseVector(3,0,1))\nbreeze.linalg.DenseVector[Double] = DenseVector(0.0, -6.0, -4.0)\n\nscala> f.calculate(DenseVector(0,0))\n(Double, breeze.linalg.DenseVector[Double]) = (18.0,DenseVector(-6.0, -6.0))\n```\n\nYou can also use approximate derivatives, if your function is easy enough to compute:\n\n```scala\nscala> def g(x: DenseVector[Double]) = (x - 3.0):^ 2.0 sum\n\nscala> g(DenseVector(0.,0.,0.))\nDouble = 27.0\n\nscala> val diffg = new ApproximateGradientFunction(g)\n\nscala> diffg.gradientAt(DenseVector(3,0,1))\nbreeze.linalg.DenseVector[Double] = DenseVector(1.000000082740371E-5, -5.999990000127297, -3.999990000025377)\n```\n\nOk, now let's optimize `f`. The easiest routine to use is just `LBFGS`, which is a quasi-Newton method that works well for most problems.\n\n```scala\nscala> val lbfgs = new LBFGS[DenseVector[Double]](maxIter=100, m=3) // m is the memory. anywhere between 3 and 7 is fine. The larger m, the more memory is needed.\n\nscala> val optimum = lbfgs.minimize(f,DenseVector(0,0,0))\noptimum: breeze.linalg.DenseVector[Double] = DenseVector(2.9999999999999973, 2.9999999999999973, 2.9999999999999973)\n\nscala> f(optimum)\nDouble = 2.129924444096732E-29\n```\n\nThat's pretty close to 0! You can also use a configurable optimizer, using `FirstOrderMinimizer.OptParams`. It takes several parameters:\n\n```scala\ncase class OptParams(batchSize:Int = 512,\n regularization: Double = 1.0,\n alpha: Double = 0.5,\n maxIterations:Int = -1,\n useL1: Boolean = false,\n tolerance:Double = 1E-4,\n useStochastic: Boolean= false) {\n // ...\n}\n```\n\n`batchSize` applies to `BatchDiffFunctions`, which support using small minibatches of a dataset. `regularization` integrates L2 or L1 (depending on `useL1`) regularization with constant lambda. `alpha` controls the initial stepsize for algorithms that need it. `maxIterations` is the maximum number of gradient steps to be taken (or -1 for until convergence). `tolerance` controls the sensitivity of the \nconvergence check. Finally, `useStochastic` determines whether or not batch functions should be optimized using a stochastic gradient algorithm (using small batches), or using LBFGS (using the entire dataset).\n\n`OptParams` can be controlled using `breeze.config.Configuration`, which we described earlier.\n\n### breeze.optimize.linear\n\nWe provide a DSL for solving linear programs, using Apache's Simplex Solver as the backend. This package isn't industrial strength yet by any means, but it's good for simple problems. The DSL is pretty simple:\n\n```scala\nimport breeze.optimize.linear._\nval lp = new LinearProgram()\nimport lp._\nval x0 = Real()\nval x1 = Real()\nval x2 = Real()\n\nval lpp = ( (x0 + x1 * 2 + x2 * 3 )\n subjectTo ( x0 * -1 + x1 + x2 <= 20)\n subjectTo ( x0 - x1 * 3 + x2 <= 30)\n subjectTo ( x0 <= 40 )\n)\n\nval result = maximize( lpp)\n\nassert( norm(result.result - DenseVector(40.0,17.5,42.5), 2) < 1E-4)\n```\n\nWe also have specialized routines for bipartite matching (`KuhnMunkres` and `CompetitiveLinking`) and flow problems.\n\n## Breeze-Viz\n\n**This API is highly experimental. It may change greatly. **\n\nBreeze continues most of the functionality of Scalala's plotting facilities, though the API is somewhat different (in particular, more object oriented.) These methods are documented in scaladoc for the traits in the `breeze.plot` package object. First, let's plot some lines and save the image to file. All the actual plotting work is done by the excellent [`JFreeChart`](http://www.jfree.org/jfreechart/) library.\n\n```scala\nimport breeze.linalg._\nimport breeze.plot._\n\nval f = Figure()\nval p = f.subplot(0)\nval x = linspace(0.0,1.0)\np += plot(x, x :^ 2.0)\np += plot(x, x :^ 3.0, '.')\np.xlabel = \"x axis\"\np.ylabel = \"y axis\"\nf.saveas(\"lines.png\") // save current figure as a .png, eps and pdf also supported\n```\n\n\nThen we'll add a new subplot and plot a histogram of 100,000 normally distributed random numbers into 100 buckets.\n\n```scala\nval p2 = f.subplot(2,1,1)\nval g = breeze.stats.distributions.Gaussian(0,1)\np2 += hist(g.sample(100000),100)\np2.title = \"A normal distribution\"\nf.saveas(\"subplots.png\")\n```\n\n\nBreeze also supports the Matlab-like \"image\" command, here imaging a random matrix.\n\n```scala\nval f2 = Figure()\nf2.subplot(0) += image(DenseMatrix.rand(200,200))\nf2.saveas(\"image.png\")\n```\n\n\n## Where to go next?\n\nAfter reading this quickstart, you can go to other wiki pages, especially [Linear Algebra Cheat-Sheet](https://github.com/scalanlp/breeze/wiki/Linear-Algebra-Cheat-Sheet) and [Data Structures](https://github.com/scalanlp/breeze/wiki/Data-Structures).\n","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"556b7524-1106-40a8-90ce-1e2aa67aa7bf"},{"version":"CommandV1","origId":68426,"guid":"8cf79628-f7b1-4a06-b23f-919e601eb50e","subtype":"command","commandType":"auto","position":1.5,"command":"%md\n#### Big O Notation for Space and Time Complexity by Ameet Talwalkar in BerkeleyX: CS190.1x Scalable Machine Learning\n**(watch later 5:52)**:\n\n[](https://www.youtube.com/v/SmsEzDXb3c0?rel=0&autoplay=1&modestbranding=1&start=1)","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"9e334380-8ccf-4c1f-9397-e2eaf519fe40"},{"version":"CommandV1","origId":68427,"guid":"8154769f-b322-4983-9e75-a0c0eb4888a8","subtype":"command","commandType":"auto","position":1.75,"command":"%md\nWatch this and take notes!","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"1ecb9690-b218-48c4-8620-bf65b4e55f5d"},{"version":"CommandV1","origId":44157,"guid":"ca043c90-1a30-4d20-9df7-7ebf75c8b97b","subtype":"command","commandType":"auto","position":2.0,"command":"%md\n\n# [Scalable Data Science](http://www.math.canterbury.ac.nz/~r.sainudiin/courses/ScalableDataScience/)\n\n\n### prepared by [Raazesh Sainudiin](https://nz.linkedin.com/in/raazesh-sainudiin-45955845) and [Sivanand Sivaram](https://www.linkedin.com/in/sivanand)\n\n*supported by* [](https://databricks.com/)\nand \n[](https://www.awseducate.com/microsite/CommunitiesEngageHome)","commandVersion":0,"state":"finished","results":null,"errorSummary":null,"error":null,"startTime":0.0,"submitTime":0.0,"finishTime":0.0,"collapsed":false,"bindings":{},"inputWidgets":{},"displayType":"table","width":"auto","height":"auto","xColumns":null,"yColumns":null,"pivotColumns":null,"pivotAggregation":null,"customPlotOptions":{},"commentThread":[],"commentsVisible":false,"parentHierarchy":[],"diffInserts":[],"diffDeletes":[],"globalVars":{},"latestUser":"","commandTitle":"","showCommandTitle":false,"hideCommandCode":false,"hideCommandResult":false,"iPythonMetadata":null,"nuid":"fe4ffa3e-9861-4f63-add1-344a4be08aed"}],"dashboards":[],"guid":"32c5bbdd-1b5a-4b5a-ae37-e554bf7c97d3","globalVars":{},"iPythonMetadata":null,"inputWidgets":{}};</script> <script src="https://databricks-prod-cloudfront.cloud.databricks.com/static/201602081754420800-0c2673ac858e227cad536fdb45d140aeded238db/js/notebook-main.js" onerror="window.mainJsLoadError = true;"></script> </head> <body> <script> if (window.mainJsLoadError) { var u = 'https://databricks-prod-cloudfront.cloud.databricks.com/static/201602081754420800-0c2673ac858e227cad536fdb45d140aeded238db/js/notebook-main.js'; var b = document.getElementsByTagName('body')[0]; var c = document.createElement('div'); c.innerHTML = ('<h1>Network Error</h1>' + '<p><b>Please check your network connection and try again.</b></p>' + '<p>Could not load a required resource: ' + u + '</p>'); c.style.margin = '30px'; c.style.padding = '20px 50px'; c.style.backgroundColor = '#f5f5f5'; c.style.borderRadius = '5px'; b.appendChild(c); } </script> </body> </html>