Mathematical Operations on Arrays in Julia - GeeksforGeeks

26 May, 2020
With the help of Mathematical Operations, we can perform addition, subtraction, multiplication, division, and many more to compute the result between two matrices or arrays. Mathematical operations are a very crucial part of any high-level programming language. In the world of Julia to compete with languages like python and java, Julia is also enabled with the same functionality but have different syntax.
Mathematical Operations :
We can add two arrays with the help of + operator.
Example of 1D array :
# Define and declare the 1D arraysA = [1 2 3] # Shape 1X3B = [4 5 10] # Shape 1X3  # Adding two arraysgfg = A + Bprint(gfg)
Output:
Example of 2D array:
# Define and declare the 2D arraysA = [1 2; -1 -2] # Shape 2X2B = [4 5; 10 12] # Shape 2X2  # Adding two arraysgfg = A + Bprint(gfg)
Output:
Example of 3D array:
# Define and declare the 3D arraysA = cat([1 2 3], [-1 -2 -3], [2 1 4], dims=3) # Shape 3X3B = cat([4 5 2], [10 12 -5], [-1 2 1], dims=3) # Shape 3X3  # Adding two arraysgfg = A + Bprint(gfg)
Output:
We can subtract two arrays with the help of – operator.
Example of 1D array:
# Define and declare the 1D arraysA = [1 2 3] # Shape 1X3B = [4 5 10] # Shape 1X3  # Subtracting two arraysgfg = A - Bprint(gfg)
Output:
Example of 2D array:
# Define and declare the 2D arraysA = [1 2; -1 -2] # Shape 2X2B = [4 5; 10 12] # Shape 2X2  # Subtracting two arraysgfg = A - Bprint(gfg)
Output:
Example of 3D array:
# Define and declare the 3D arraysA = cat([1 2 3], [-1 -2 -3], [2 1 4], dims=3) # Shape 3X3B = cat([4 5 2], [10 12 -5], [-1 2 1], dims=3) # Shape 3X3  # Subtracting two arraysgfg = A - Bprint(gfg)
Output:
We can multiply two arrays with the help of * operator.
Example of 1D array:
# Define and declare the 1D arraysA = [1 2 3] # Shape 1X3B = [4; 5; 10] # Shape 3X1  # Multiplying two arraysgfg = A * Bprint(gfg)
Output:
Example of 2D array:
# Define and declare the 2D arraysA = [1 2; -1 -2] # Shape 2X2B = [4 5; 10 12] # Shape 2X2  # Multiplying two arraysgfg = A * Bprint(gfg)
Output:
Example of 3D array:
# Define and declare the 3D arraysA = cat([1 2 3], [-1 -2 -3], [2 1 4], dims=3) # Shape 3X3B = cat([4 5 2], [10 12 -5], [-1 2 1], dims=3) # Shape 3X3  # Multiplying two arraysgfg = A * Bprint(gfg)
Output:
We can division two arrays with the help of / operator.
Example of 1D array:
# Define and declare the 1D arraysB = [1 2 3] # Shape 1X3A = [4 5 10] # Shape 1X3  # Dividing two arraysgfg = A / Bprint(gfg)
Output:
Example of 2D array:
# Define and declare the 2D arraysB = [1 2; 1 2] # Shape 2X2A = [4 5; 10 12] # Shape 2X2  # Dividing two arraysgfg = B / Aprint(gfg)
Output:
Example of 3D array:
# Define and declare the 3D arraysA = cat([1 2 3], [-1 -2 -3], [2 1 4], dims=3) # Shape 3X3B = cat([4 5 2], [10 12 -5], [-1 2 1], dims=3) # Shape 3X3  # Dividing two arraysgfg = B / Aprint(gfg)
Output:
Picked
Julia
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
String concatenation in Julia
Vectors in Julia
Storing Output on a File in Julia
Reshaping array dimensions in Julia | Array reshape() Method
Formatting of Strings in Julia
Creating array with repeated elements in Julia - repeat() Method
Getting rounded value of a number in Julia - round() Method
Comments in Julia
Get array dimensions and size of a dimension in Julia - size() Method
while loop in Julia