Matrices in Julia are the heterogeneous type of containers and hence, they can hold elements of any data type. It is not mandatory to define the data type of a matrix before assigning the elements to the matrix. Julia automatically decides the data type of the matrix by analyzing the values assigned to it. Because of the ordered nature of a matrix, it makes it easier to perform operations on its values based on their index.
Following are some common matrix manipulation operations in Julia:
- Transpose of a matrix
- Flipping a matrix
- Concatenating matrices
- Reshaping a matrix
- Inverse of a matrix
Creating a matrix
Julia provides a very simple notation to create matrices. A matrix can be created using the following notation: A = [1 2 3; 4 5 6]. Spaces separate entries in a row and semicolons separate rows. We can also get the size of a matrix using size(A).
Transpose of a matrix
- The transpose operation flips the matrix over its diagonal by switching the rows and columns.
- Let A be a matrix. We can get the transpose of A by using A’.
Flipping a matrix:
- A matrix in Julia can be flipped via the X-axis i.e. horizontally or via the Y-axis i.e. vertically.
- To flip the matrix we use
reverse(< matrix >, dims= < 1 or 2 >))1 = vertically, 2 = horizontally.
Example 1: Flipping vertically
Example 2: Flipping horizontally
- In Julia we can concatenate a matrix to another matrix to the right side of the initial matrix or to the bottom of it.
- We use
vcat(A, B)to concatenate to the side.
hcat(A, B)to concatenate to the bottom.
- While concatenating to the side, we need to make sure that both the matrices have same number of rows.
- While concatenating to the bottom, we need to make sure that both the matrices have same number of columns.
Example 1: Concatenate to the side
Example 2: Concatenate to the bottom
Reshaping a matrix
We can reshape a matrix into another matrix of different size.
Example 1: Reshaping a matrix
Reshaping the matrix to size (2, 3)
Reshaping the matrix to size (6, 1)
Reshaping the matrix to size (1, 6)
Inverse of a matrix
- If A is a square matrix its multiplicative inverse is called its inverse matrix. Denoted by A-1.
- In Julia we use
inv(A)to get the inverse of the matrix A.
- Mapping over Matrices in Julia
- Julia end Keyword | Marking end of blocks in Julia
- Julia function keyword | Create user-defined functions in Julia
- Julia continue Keyword | Continue iterating to next value of a loop in Julia
- Julia break Keyword | Exiting from a loop in Julia
- Julia local Keyword | Creating a local variable in Julia
- Julia global Keyword | Creating a global variable in Julia
- Operations on Matrices in R
- Combining Matrices in R
- Working with Sparse Matrices in R Programming
- Mathematical Operations on Matrices | Class 12 Maths
- Getting ceiling value of x in Julia - ceil() Method
- Getting floor value of x in Julia - floor() Method
- Getting the minimum value from a list in Julia - min() Method
- Package Management in Julia
- Visualisation in Julia
- Random Numbers Ecosystem in Julia - The Pseudo Side
- Accessing element at a specific index in Julia - getindex() Method
- Get size of string in Julia - sizeof() Method
- Reverse a string in Julia - reverse() Method
Example 1: Getting the Inverse of a matrix
Example 2: Getting Identity Matrix
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.