nimble.identity

nimble.identity(size, pointNames='automatic', featureNames='automatic', returnType='Matrix', name=None)

Return a data object representing an identity matrix.

The returned object will always be a square with the number of points and features equal to size. The main diagonal will have values of 1 and every other value will be zero.

Parameters:
  • size (int) – The number of points and features in the returned object.

  • pointNames ('automatic', list, dict) – Names to be associated with the points in the returned object. If ‘automatic’, default names will be generated. Otherwise, may be specified explictly by some list-like or dict-like object, so long as all points in the data are assigned a name and the names for each point are unique.

  • featureNames ('automatic', list, dict) – Names to be associated with the features in the returned object. If ‘automatic’, default names will be generated. Otherwise, may be specified explictly by some list-like or dict-like object, so long as all features in the data are assigned a name and the names for each feature are unique.

  • returnType (str) – May be any of the allowed types specified in nimble.core.data.available. Default is “Matrix”.

  • name (str, None) – A string describing the data that will display when printing or logging the returned object. This value is also set as the name attribute of the returned object.

Returns:

nimble.core.data.Base – Subclass of Base object corresponding with the returnType.

See also

ones, zeros

Examples

Identity matrix with default names.

>>> identity = nimble.identity(5)
>>> identity
<Matrix 5pt x 5ft
     0  1  2  3  4
   ┌──────────────
 0 │ 1  0  0  0  0
 1 │ 0  1  0  0  0
 2 │ 0  0  1  0  0
 3 │ 0  0  0  1  0
 4 │ 0  0  0  0  1
>

Named object of zeros with pointNames and featureNames.

>>> identityList = nimble.identity(3, returnType="List",
...                                pointNames=['1', '2', '3'],
...                                featureNames=['a', 'b', 'c'],
...                                name='identity matrix list')
>>> identityList
<List "identity matrix list" 3pt x 3ft
     a  b  c
   ┌────────
 1 │ 1  0  0
 2 │ 0  1  0
 3 │ 0  0  1
>

Keywords: identity matrix, square, diagonal, one, eye