"/>

how to create a variable matrix depending on an index

I am trying to create the following type of matrix using scipy or numpy.

A_1 = diag(0.5, 0, 0, ...., 0)
A_k = diag(0,0, ..., 1, 0, 0, ....,0) for each 1 < k < N
A_N = diag(0, 0, ...., 0, 0.5)

Essentially A_ks are a series of a diagonal matrices such that each A_k has a 1 in the kth position of the diagonal for 1 < k < N and A_1 is a diagonal matrix with 0.5 in the (1,1) position zeros everywhere else and A_N is a diagonal matrix with 0.5 in the (N,N) position and zeros everywhere else.

I know I can use the sparse matrices in scipy and I know how to create each individual matrix. But how do I create the entire series of matrices asa function that can be called depending on k?

Read Full News
Submit your Tech Updates