With “regular” numpy arrays, using numpy.diag:
def tridiag(a, b, c, k1=-1, k2=0, k3=1):
return np.diag(a, k1) + np.diag(b, k2) + np.diag(c, k3)
a = [1, 1]; b = [2, 2, 2]; c = [3, 3]
A = tridiag(a, b, c)
More Related Contents:
- Difference between numpy.array shape (R, 1) and (R,)
- What are the differences between numpy arrays and matrices? Which one should I use?
- Very large matrices using Python and NumPy
- numpy matrix vector multiplication [duplicate]
- Numpy matrix to array
- how does multiplication differ for NumPy Matrix vs Array classes?
- Bin elements per row – Vectorized 2D Bincount for NumPy
- Convolve2d just by using Numpy
- Numpy ‘smart’ symmetric matrix
- Convert a 1D array to a 2D array in numpy
- numpy get index where value is true
- Deprecation status of the NumPy matrix class
- Efficiently Calculating a Euclidean Distance Matrix Using Numpy
- Iterating over Numpy matrix rows to apply a function each?
- how to perform max/mean pooling on a 2d array using numpy
- How to get element-wise matrix multiplication (Hadamard product) in numpy?
- Why does numpy.linalg.solve() offer more precise matrix inversions than numpy.linalg.inv()?
- NumPy array/matrix of mixed types
- Replace sub part of matrix by another small matrix in numpy
- How to convert a column or row matrix to a diagonal matrix in Python?
- Is there a standard solution for Gauss elimination in Python?
- How to find linearly independent rows from a matrix
- Convert row vector to column vector in NumPy
- Numpy select rows based on condition
- How to find the pairwise differences between rows of two very large matrices using numpy?
- Multiple matrix multiplication
- A numpy array unexpectedly changes when changing another one despite being separate
- Interweaving two numpy arrays
- Stocking large numbers into numpy array
- Index all *except* one item in python