How to generate a usable tensor product of two matrices in Python


<a href="https://stackoverflow.com/questions/16296028/tensor-dot-operation-in-python" rel="nofollow">This thread</a> successfully answers how to use numpy to calculate the tensor product of two matrices in Python. However, I want the output to be in a proper matrix format so that further calculations can be performed on it without my manually editing it.

For instance,

I=matrix([[1,0],[0,1]]) print np.tensordot(I, I, axes=0)

Gives the output:

[[[[1 0] [0 1]] [[0 0] [0 0]]] [[[0 0] [0 0]] [[1 0] [0 1]]]]

I want it in the form:


so that I can perform further operations on it within the program itself.

How do I do this?


The Kronecker tensor product can be calculated using <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.kron.html" rel="nofollow">numpy.kron</a>.


  • Matrix power for sparse matrix in python
  • what does Tilde image mean in MATLAB?
  • Resource for understanding view, projection, 'virtual camera' in OpenGL or graphics in gen
  • Ordering of eigenvectors when calculating eigenvectors using LAPACK's ssteqr
  • YAJSW window service did not start
  • how to use asyncio with boost.python?
  • proxy request in node.js / express
  • C++ Armadillo Access Triangular Matrix Elements
  • Pointer vs Reference difference when passing Eigen objects as arguments
  • Not able to display correct data in table -AngularJS
  • MAVEN : Run Multiple Maven Project using Maven Test
  • How to implement Deep Linking in Roku SG application?
  • import scipy.sparse failed
  • how to set variables in a php include file?
  • quiver not drawing arrows just lots of blue, matlab
  • During installation of Django, why do I keep getting ImportError: No module named django?
  • where do I find the xml.dom python package for the python-2.6.0-8.9.28 and I have a suse/x86_64 vers
  • Python pickle not one-to-one: different pickles give same object
  • Android Activity.onWindowFocusChanged doesn't get called from within TabHost
  • Invalid object name 'dbo.Item'
  • Jenkins: FATAL: Could not initialize class hudson.util.ProcessTree$UnixReflection
  • TextToSpeech.setEngineByPackageName() triggers NullPointerException
  • How to define and use opencv mat of user type
  • Extracting HTML between tags
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • Javascript Callbacks with Object constructor
  • Deserializing XML into class C#
  • vba code to select only visible cells in specific column except heading
  • How do I use the BLAS library provided by MATLAB?
  • Font Awesome Showing Box instead of Icons
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • Properly structure and highlight a GtkPopoverMenu using PyGObject
  • php design question - will a Helper help here?
  • Proper folder structure for lots of source files
  • python draw pie shapes with colour filled
  • Is it possible to post an object from jquery to bottle.py?
  • Is there any way to bind data to data.frame by some index?
  • How to Embed XSL into XML
  • How can I use `wmic` in a Windows PE script?
  • Python/Django TangoWithDjango Models and Databases