Skip to content

pycauset.identity

pycauset.identity(x)

Creates an identity-like matrix (ones on the diagonal, zeros elsewhere) with shape derived from x.

This is a convenience factory around pycauset.IdentityMatrix and supports multiple input forms.

Parameters

x can be:

  1. Integer N
  2. Returns an \(N \times N\) identity matrix.

  3. Shape sequence [rows, cols]

  4. Returns a rows × cols identity-like matrix.
  5. The diagonal is filled with ones up to \(\min(rows, cols)\).

  6. A Matrix or Vector

  7. If x is a matrix, returns an identity-like matrix with shape (x.rows(), x.cols()).
  8. If x is a vector, returns an \(N \times N\) identity matrix where \(N = x.size()\).

Examples

import pycauset as pc

# 1) Integer input
I5 = pc.identity(5)            # 5x5

# 2) Rectangular shape input
I35 = pc.identity([3, 5])      # 3x5

# 3) Matrix input
A = pc.FloatMatrix(2, 4)
IA = pc.identity(A)            # 2x4

# 3) Vector input
v = pc.IntegerVector(7)
Iv = pc.identity(v)            # 7x7

See also