baypy¶
- dot_product(data: DataFrame, regressors: dict) ndarray¶
Computes the dot product between columns of
dataand values ofregressors.Parameters¶
- datapandas.DataFrame
The dataframe to be used for the dot product. It cannot be empty. It must contain all
regressorskeys.- regressorsdict
Dictionary with regressors’ values. It cannot be empty. All regressors and relative values must be a key-value pair.
Returns¶
- numpy.ndarray
Array of computed dot product. Each element is the dot product of a
datarow with respect to eachregressors. It has the same length ofdata.
Raises¶
- TypeError
If
datais not apandas.DataFrame,if
regressorsis not adict,if a
regressorsvalue is not aintor afloat.
- KeyError
If a
regressorskey is not a column ofdata.- ValueError
If
datais an emptypandas.DataFrame,if
regressorsis an emptydict.
Examples¶
>>> import pandas as pd >>> data = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]}) >>> regressors = {'a': 2, 'b': -1} >>> dot_product(data = data, regressors = regressors) >>> array([-2, -1, 0])
- flatten_matrix(matrix: ndarray) ndarray¶
Flattens a matrix of dimensions
(M, N)to(M*N, ).Parameters¶
- matrixnumpy.ndarray
Matrix with
Mrows andNcolumns.
Returns¶
- numpy.ndarray
Flatten array with
M*Nelements.
Raises¶
- TypeError
If
matrixis not anumpy.ndarray.- ValueError
If
matrixis an emptynumpy.ndarray.
Examples¶
>>> import numpy >>> a = numpy.array([[1, 2], [3, 4], [5, 6]]) >>> a >>> array([[1, 2], ... [3, 4], ... [5, 6]]) >>> flatten_matrix(a) >>> array([1, 2, 3, 4, 5, 6])
- matrices_to_frame(matrices_dict: dict) DataFrame¶
Organizes a dictionary of matrices in a
pandas.DataFrame. Each matrix becomes a frame column, with column name equal to the matrix’ relative key in the dictionary. If the matrix has dimensions(M, N), then the relative frame column has lengthM*N.Parameters¶
- matrices_dictdict
Dictionary of matrices to be organized. Matrices and relative names are key-value pairs. Each matrix is a
numpy.ndarraywith dimensions(M, N).
Returns¶
- pandas.DataFrame
Reorganized matrices frame. Matrices are organized in a
pandas.DataFrame, one for each column. The length of the frame isM*N.
Raises¶
- TypeError
If
matrices_dictis not adict,if a
matrices_dictvalue is not anumpy.ndarray.
- ValueError
If a
matrices_dictvalue is an emptynumpy.ndarray.
Examples¶
>>> import numpy >>> a = numpy.array([[1, 2], [3, 4], [5, 6]]) >>> b = numpy.array([[7, 8], [9, 10], [11, 12]]) >>> d = {'a': a, 'b': b} >>> matrices_to_frame(d) >>> a b >>> 0 1 7 >>> 1 2 8 >>> 2 3 9 >>> 3 4 10 >>> 4 5 11 >>> 5 6 12