python - Using linalg.block_diag for variable number of blocks -


Then I have a code that generates different metrics, these metrics need to be stored in block diagonal matrix. It should be quite simple because I can use the tip:

  scipy.linalg.block_diag (* AR)  

Although I have a problem I'm not sure how many metrics will need to be stored in this way. I want to keep things as (naturally) as possible. I thought of doing something like this:

  scipy.linalg.block_diag (matrix_list [ii] for category ii (len (matrix_list)))  

but It does not work. I can think of some other ways to do this ... but they become quite complicated for everything I think should be very simple.

Does anyone have an idea (or know) out of it?

Thanks in advance!

When you do:

Going to code> a generator expression scipy.linalg.block_diag (matrix_list [ii] ii in range (len ( Matrix_list))) Block_diag , which is not the way to use it.

Instead, use the * operator to expand the argument list in the function call, such as:

  scipy.linalg. Block_diag (* matrix_list)  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -