0% found this document useful (0 votes)
10 views5 pages

Array Operations: Subtraction & Multiplication

The document demonstrates array operations in R, including the creation of two 3D arrays, arr1 and arr2. It shows how to perform subtraction and multiplication on these arrays, and prints the results of each operation. The results indicate the differences and products of corresponding elements in the arrays.

Uploaded by

jyotishet308
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

Array Operations: Subtraction & Multiplication

The document demonstrates array operations in R, including the creation of two 3D arrays, arr1 and arr2. It shows how to perform subtraction and multiplication on these arrays, and prints the results of each operation. The results indicate the differences and products of corresponding elements in the arrays.

Uploaded by

jyotishet308
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Example for Arrayoperation

# Create first array

arr1 <- array(1:12, dim = c(3, 2, 2))

# Create second array

arr2 <- array(13:24, dim = c(3, 2, 2))

# Subtraction of arrays

sub_res <- arr1 - arr2

# Multiplication of arrays

mul_res <- arr1 * arr2

# Print results

print("First Array:")

print(arr1)

print("Second Array:")

print(arr2)

print("Result of Subtraction (arr1 - arr2):")

print(sub_res)

print("Result of Multiplication (arr1 * arr2):")

print(mul_res)
OUTPUT:

# Create first array

> arr1 <- array(1:12, dim = c(3, 2, 2))

> # Create second array

> arr2 <- array(13:24, dim = c(3, 2, 2))

> # Subtraction of arrays

> sub_res <- arr1 - arr2

> # Multiplication of arrays

> mul_res <- arr1 * arr2

> # Print results

> print("First Array:")

[1] "First Array:"

> print(arr1)

,,1

[,1] [,2]

[1,] 1 4

[2,] 2 5

[3,] 3 6
,,2

[,1] [,2]

[1,] 7 10

[2,] 8 11

[3,] 9 12

> print("Second Array:")

[1] "Second Array:"

> print(arr2)

,,1

[,1] [,2]

[1,] 13 16

[2,] 14 17

[3,] 15 18

,,2

[,1] [,2]

[1,] 19 22

[2,] 20 23
[3,] 21 24

> print("Result of Subtraction (arr1 - arr2):")

[1] "Result of Subtraction (arr1 - arr2):"

> print(sub_res)

,,1

[,1] [,2]

[1,] -12 -12

[2,] -12 -12

[3,] -12 -12

,,2

[,1] [,2]

[1,] -12 -12

[2,] -12 -12

[3,] -12 -12

> print("Result of Multiplication (arr1 * arr2):")

[1] "Result of Multiplication (arr1 * arr2):"


> print(mul_res)

,,1

[,1] [,2]

[1,] 13 64

[2,] 28 85

[3,] 45 108

,,2

[,1] [,2]

[1,] 133 220

[2,] 160 253

[3,] 189 288

>

You might also like