[1] "numeric"
[1] 1 2 3 4
Instance of: algebraic object / data structure
AKA: array, matrices
Distinct from: list
English: Vectors, matrices, and tensors are like lists in that they are a collection of objects which are indexed. They differ in that the index can be multi-dimensional, where vectors are 1-d indexed, matrices are 2-d indexed, and tensors are m-d indexed. They also are typically constrained to have objects that share the same type, e.g. numbers or strings.
Formalization:
\[ \]
Cites:
Array:
3Blue1Brown: Vectors | Chapter 1, Essence of linear algebra 3Blue1Brown: Linear combinations, span, and basis vectors | Chapter 2, Essence of linear algebra
https://superstudy.guide/algorithms-data-structures/data-structures/arrays-strings *Kadane’s algorithm
Matrix:
3Blue1Brown: Linear transformations and matrices | Chapter 3, Essence of linear algebra
Tensor:
Code
Vector
Note unlike matrix and array, the basic vector function initializes an empty vector and you have to actually use as.vector to coerce something else to vector as the constructor.
[1] "numeric"
[1] 1 2 3 4
Matrix
Note we can choose which direction to fill the matrix with, either by row1-col1, row1-col2, row1-col3, row1-col4
example_matrix <- matrix(c(1,2,3,4,"A","B","C","D"), nrow = 2, ncol = 4, byrow = TRUE,
dimnames = list(c("row1", "row2"),
c("C.1", "C.2", "C.3", "C.4")))
class(example_matrix)
[1] "matrix" "array"
C.1 C.2 C.3 C.4
row1 "1" "2" "3" "4"
row2 "A" "B" "C" "D"
Arrays
Note array dimensions are ordered, row, column, depth, …, M , and elements are filled row1-col1-depth1, row2-col1-depth1, row1-col2-depth1,… and so on. Note this was coerced to a string because any of the elements were a string.
example_tensor= array(c(1,2,3,4,"A","B","C","D","+","-","*","/"),dim=c(2,3,2,2))
class(example_tensor)
[1] "array"
, , 1, 1
[,1] [,2] [,3]
[1,] "1" "3" "A"
[2,] "2" "4" "B"
, , 2, 1
[,1] [,2] [,3]
[1,] "C" "+" "*"
[2,] "D" "-" "/"
, , 1, 2
[,1] [,2] [,3]
[1,] "1" "3" "A"
[2,] "2" "4" "B"
, , 2, 2
[,1] [,2] [,3]
[1,] "C" "+" "*"
[2,] "D" "-" "/"
Documentation:
Examples:
Documentation:
library(DBI)
# Create an ephemeral in-memory RSQLite database
#con <- dbConnect(RSQLite::SQLite(), dbname = ":memory:")
#dbListTables(con)
#dbWriteTable(con, "mtcars", mtcars)
#dbListTables(con)
#Configuration failed because libpq was not found. Try installing:
#* deb: libpq-dev libssl-dev (Debian, Ubuntu, etc)
#install.packages('RPostgres')
#remotes::install_github("r-dbi/RPostgres")
#Took forever because my file permissions were broken
#pg_lsclusters
require(RPostgres)
Loading required package: RPostgres
“JAX provides a multidimensional array data structure called DeviceArray that implements many typical properties and methods of the numpy.ndarray”