Definition: A multidimensional array $A$ of dimension $d$ is a collection of individual data points indexed by $n$ numbers: i.e., an individual data point is denoted by
$$A[i_1, i_2, \dots, i_d]$$where $i_l = 1,\dots, n_l$ is the index corresponding to the $l$ axis, and where $n_l$ is the number of data points stored along the $l$ axis.
The shape of an array is the tuple
$$(n_1,\dots,n_d).$$Remark 1: The dimension above is different from the notion of dimension in linear algebra, which is the number of entries in the array (i.e. $n_1n_2\dots n_d$).
Remark 2: The dimension in the definition above emphasis the fact that a multidimensional array of dimension $d$ can be geometrically regarded as a $d$ dimensinal cube of numbers sitting in $\mathbb R^d$.
In [1]:
%load_ext rmagic
In [ ]:
%%R
dim(x) = c(2,3,3)
print(class(x))
print(dim(x))
print(x)
In [ ]:
%%R
x = sample(18); dim(x) = c(2,3,3)
y = sample(18); dim(y) = c(2,3,3)
In [ ]:
%%R
z = x + y
z = x * y
z = x ^ y
In [ ]:
%%R
print(z)
In [ ]:
%%R
x = sample(c(T,F), 18, replace=T)
y = sample(c(T,F), 18, replace=T)
print(y)
In [ ]:
%%R
dim(x) = c(2,3,3)
dim(y) = c(2,3,3)
print(x | y) # Python Or
print(x & y) # Python And
print(!x) # Python Not
In [ ]:
%%R
x = sample(c('A','C','G','T'), 18, replace=T)
y = sample(c('A','C','G','T'), 18, replace=T)
print(x)
In [ ]:
%%R
dim(x) = c(2,3,3)
dim(y) = c(2,3,3)
In [ ]:
%%R
z = paste(x, y, sep='')
print(z)
In [ ]:
%%R
dim(z) = c(2,3,3)
print(z)
In [5]:
%%R
A = sample(64)
dim(A) = c(8, 8)
print(class(A))
print(A)
In [7]:
%%R
print(A[2,3])
In [11]:
%%R
print(A[c(4, 1, 5), c(4,2)])
In [12]:
%%R
A[c(4,1,5), c(4,2)] = 999
print(A)
In [17]:
%%R
ind = (A > 50) & (A < 80)
print(ind)
In [18]:
%%R
print(A[ind])
In [19]:
%%R
A[ind] = 0
print(A)
In [27]:
%%R
x = c(1,2,3,4)
y =1
In [32]:
%%R
z = x + y
print(z)
In [34]:
%%R
x = c(1, 2, 3, 4)
y = c(10, 100, 0 )
z = x * y
print(z)
In [ ]:
In [35]:
%%R
x = sample(5)
print(x)
In [42]:
%%R
f = function(x) x^x
In [43]:
%%R
z = f(x)
print(z)
In [44]:
%%R
g = function(x) c(x^x, x * x, x + x)
In [47]:
%%R
z = g(2)
print(z)
In [49]:
%%R
z = g(c(1, 2, 3))
print(z)
In [51]:
%%R
z = sapply(c(1,2,3), g)
print(z)
In [52]:
%%R
S = sum(z)
print(S)
In [55]:
%%R
stdGrade = apply(z, 1, mean)
print(stdGrade)
In [56]:
%%R
examAvg = apply(z, 2, mean)
print(examAvg)
In [57]:
%%R
A = sample(27)
dim(A) = c(3,3,3)
print(A)
In [60]:
%%R
Z = apply(A, 1, mean)
print(Z)
In [280]:
%%R -r 86 -w 400 -h 300
n = 81
#x = rnorm(n, mean=50, sd=10)
x = runif(n, min=0, max=100)
#print(x)
hist(x, xlim=c(-10, 110), ylim=c(0, n/2))
In [282]:
%%R
x = round(x)
dim(x) = c(9,9)
print(x)
In [285]:
%%R
exam = rnorm(10, mean = 70, sd=30)
print(exam)
In [295]:
%%R
gradeBook = replicate(2, rnorm(10, mean=40, sd=79))
print(gradeBook)
In [296]:
%%R
A = sample(25)
dim(A) = c(5,5)
print(A)
In [301]:
%%R
B = sample(1:100, 5)
dim(B) = c(5, 1)
print(B)
print(class(B))
In [302]:
%%R
C = A %*% B
print(C)
In [303]:
%%R
AInv = solve(A)
print(AInv)
In [306]:
%%R
D = A %*% AInv
print(round(D))
print(typeof(D[1,1]))
In [309]:
%%R
d = det(A)
print(d)
In [ ]: