The data type used to hold a combined date and time value.
The Gregorian calendar was introduced in 1582. The Proleptic Gregorian Calendar is sometimes used for earlier dates, but in the Proleptic Gregorian Calendar the year 1 CE is preceded by the year 1 BCE. The MATLAB epoch thus starts at the beginning of the year 1 BCE, but uses a zero to refer to this year.
The data type used to hold the difference between two date/time types.
How to get the year, the month as an integer from 1 through 12, and the day of the month from a date/time value.
In Octave, but not MATLAB, one can use index notation on the return value of a function:
How to get the hour as an integer from 0 through 23, the minute, and the second from a date/time value.
How to build a date/time value from the year, month, day, hour, minute, and second as integers.
How to convert a date value to a string using the default format for the locale.
How to parse a date/time value from a string in the manner of strptime from the C standard library.
How to write a date/time value to a string in the manner of strftime from the C standard library.
Permitted data types for array elements.
Arrays in Octave can only contain numeric elements.
Array literals can have a nested structure, but Octave will flatten them. The following literals create the same array:
Logical values can be put into an array because true and false are synonyms for 1 and 0. Thus the following literals create the same arrays:
If a string is encountered in an array literal, the string is treated as an array of ASCII values and it is concatenated with other ASCII values to produce as string. The following literals all create the same string:
If the other numeric values in an array literal that includes a string are not integer values that fit into a ASCII byte, then they are converted to byte sized values.
Array literals can have a nested structure, but R will flatten them. The following literals produce the same array of 6 elements:
If an array literal contains a mixture of booleans and numbers, then the boolean literals will be converted to 1 (for TRUE and T) and 0 (for FALSE and F).
If an array literal contains strings and either booleans or numbers, then the booleans and numbers will be converted to their string representations. For the booleans the string representations are “TRUE'” and “FALSE”.
The syntax, if any, for an array literal.
The array literal
will create an array with 5 elements of class char.
How to make an address copy, a shallow copy, and a deep copy of an array.
After an address copy is made, modifications to the copy also modify the original array.
After a shallow copy is made, the addition, removal, or replacement of elements in the copy does not modify of the original array. However, if elements in the copy are modified, those elements are also modified in the original array.
A deep copy is a recursive copy. The original array is copied and a deep copy is performed on all elements of the array. No change to the contents of the copy will modify the contents of the original array.
An arithmetic sequence is a sequence of numeric values in which consecutive terms have a constant difference.
An arithmetic sequence with a difference of 1.
An arithmetic sequence with a difference of 10.
An arithmetic sequence with a difference of 0.1.
An arithmetic sequence where the difference is computed using the start and end values and the number of elements.
How to iterate over an arithmetic sequence.
How to convert an arithmetic sequence to an array.
Multidimensional arrays are a generalization of arrays which map tuples of integers to values. All tuples in the domain of a multidimensional array have the same length; this length is the dimension of the array.
The multidimensional arrays described in this sheet are homogeneous, meaning that the values are all of the same type. This restriction allows the implementation to store the values of the multidimensional array in a contiguous region of memory without the use of references or points.
Multidimensional arrays should be contrasted with nested arrays. When arrays are nested, the innermost nested arrays contain the values and the other arrays contain references to arrays. The syntax for looking up a value is usually different:
How to get the type of the values stored in a multidimensional array.
How to benchmark code.
The basic data type of MATLAB is a matrix of floats. There is no distinction between a scalar and a 1×1 matrix, and functions that work on scalars typically work on matrices as well by performing the scalar function on each entry in the matrix and returning the results in a matrix with the same dimensions. Operators such as the logical operators (‘ ‘ ‘|’ ‘!’), relational operators (‘==’, ‘!=’, ‘ ‘, ‘ ‘), and arithmetic operators (‘+’, ‘-‘) all work this way. However the multiplication ‘*’ and division ‘/’ operators perform matrix multiplication and matrix division, respectively. The .* and ./ operators are available if entry-wise multiplication or division is desired.
Floats are by default double precision; single precision can be specified with the single constructor. MATLAB has convenient matrix literal notation: commas or spaces can be used to separate row entries, and semicolons or newlines can be used to separate rows.
Arrays and vectors are implemented as single-row (1xn ) matrices. As a result an n -element vector must be transposed before it can be multiplied on the right of a mxn matrix.
Numeric literals that lack a decimal point such as 17 and -34 create floats, in contrast to most other programming languages. To create an integer, an integer constructor which specifies the size such as int8 and uint16 must be used. Matrices of integers are supported, but the entries in a given matrix must all have the same numeric type.
Strings are implemented as single-row (1xn ) matrices of characters. Matrices cannot contain strings. If a string is put in matrix literal, each character in the string becomes an entry in the resulting matrix. This is consistent with how matrices are treated if they are nested inside another matrix. The following literals all yield the same string or 1xn matrix of characters:
true and false are functions which return matrices of ones and zeros. The ones and zeros have type logical instead of double. which is created by the literals 1 and 0. Other than having a different class, the 0 and 1 of type logical behave the same as the 0 and 1 of type double .
MATLAB has a tuple type (in MATLAB terminology, a cell array) which can be used to hold multiple strings. It can also hold values with different types.
The primitive data types of R are vectors of floats, vectors of strings, and vectors of booleans. There is no distinction between a scalar and a vector with one entry in it. Functions and operators which accept a scalar argument will typically accept a vector argument, returning a vector of the same size with the scalar operation performed on each the entries of the original vector.
The scalars in a vector must all be of the same type, but R also provides a list data type which can be used as a tuple (entries accessed by index), record (entries accessed by name), or even as a dictionary.
In addition R provides a data frame type which is a list (in R terminology) of vectors all of the same length. Data frames are equivalent to the data sets of other statistical analysis packages.
NumPy is a Python library which provides a data type called array. It differs from the Python list data type in the following ways:
- N-dimensional. Although the list type can be nested to hold higher dimension data, the array can hold higher dimension data in a space efficient manner without using indirection.
- homogeneous. The elements of an array are restricted to be of a specified type. The NumPy library introduces new primitive types not available in vanilla Python. However, the element type of an array can be object which permits storing anything in the array.
In the reference sheet the array section covers the vanilla Python list and the multidimensional array section covers the NumPy array .
List the NumPy primitive types
SciPy, Matplotlib, and Pandas are libraries which depend on Numpy.