larry methods¶
The larry methods can be divided into the following broad categories:
Methods and examples
Below you’ll find the methods in each category along with examples. All of the examples assume that you have already imported larry:
>>> from la import larry
The reference guide for the larry functions, as opposed to methods, can be found in larry functions.
Unary¶
The unary functions (such as log, sqrt, sign) operate on a single larry and do not change its shape or ordering.
Binary methods¶
The binary methods (such as +, -, / and *) combine a larry with a scalar, Numpy array, or another larry. More general binary functions, that give you control of the join method and the fill method can be found in Binary functions.
Reduce¶
The reduce methods (such as sum and std) aggregate along an axis or axes thereby reducing the dimension of the larry.
Comparison¶
The comparison methods, such as ==, >, and !=, perform an element-by-element comparison and return a bool larry. For example:
>>> y1 = larry([1, 2, 3, 4])
>>> y2 = larry([1, 9, 3, 9])
>>> y1 == y2
label_0
0
1
2
3
x
array([ True, False, True, False], dtype=bool)
and
>>> from la import larry
>>> y1 = larry([1, 2], [['a', 'b']])
>>> y2 = larry([1, 2], [['b', 'c']])
>>> y1 == y2
label_0
b
x
array([False], dtype=bool)
A larry can be compared with a scalar, NumPy array, list, tuple, and another larry.
Warning
Do not compare a NumPy array on the left-hand side with a larry on the right-hand side. You will get unexpected results. To compare a larry to a NumPy array, put the array on the right-hand side.
Get and set¶
The get methods return subsets of a larry through indexing and the set methods assign values to a subset of a larry.
Group¶
The group methods allow you to calculate the group mean (or median or ranking) along axis=0 of a larry. For example, let’s calculate the group mean of y where group 1 is (‘e’, ‘a’), group 2 is (‘d’, ‘c’), and group 3 is (‘b’):
>>> from la import larry
>>> y = larry([[1], [2], [3], [4], [5]], [['a', 'b', 'c', 'd', 'e'], [0]])
>>> group = larry([1, 1, 2, 2, 3], [['e', 'a', 'd', 'c', 'b']])
>>> y.group_mean(group)
label_0
a
b
c
d
e
label_1
0
x
array([[ 3. ],
[ 2. ],
[ 3.5],
[ 3.5],
[ 3. ]])
Missing data¶
NaNs are treated as missing data in larry:
>>> import la
>>> y = larry([1.0, la.nan])
>>> y.sum()
1.0
Missing value makers for various dtypes:
dtype | missing marker |
---|---|
float | NaN |
object | None |
str | ‘’ |
int, bool, etc | Not supported |
Size, shape, dtype¶
Here are the methods that tell you about the size, shape, and dtype of larry. Some of the methods (T, flatten, unflatten) change the shape of the larry.
Conversion¶
Methods to convert larrys to other formats. For the corresponding ‘from’ methods, see Creation.