Posts tagged with: python

de-importing a Python module with a simple function

Sometimes it is eluding to de-importing some of the python modules especially dwelling on IPython since you have changes something on the module and IPython does not see those  changes even you import the module again. The solution of such a problem is to de-import the module and import again. Here is the function that de-import the staff.




Setting up cudamat in Ubuntu Machine

cudamat is a python library that makes you available to use CUDA benefits from Python instead of intricate low level approaches. This interface uses also

Before follow these steps please make sure that you installed a working CUDA library.

  1. Download cudamat from
  2. Compile with ‘make’ in the root downloaded folder /path/to/cudamat
  3. Set the environment variables to include cudamat in PYTHONPATH to be able to imported by any script. Run followings in the command line.
     export PYTHONPATH
  4. You are ready to use cudamat.

Here is a simple code you might test;

 # -*- coding: utf-8 -*-
 import numpy as np
 import cudamat as cm
 # create two random matrices and copy them to the GPU
 a = cm.CUDAMatrix(np.random.rand(32, 256))
 b = cm.CUDAMatrix(np.random.rand(256, 32))
 # perform calculations on the GPU
 c =, b)
 d = c.sum(axis = 0)
 # copy d back to the host (CPU) and print
 print d.asarray()

Note: If you get any other path problem, it would be related to CUDA installation therefore check environment parameters need to be set for CUDA.