Search

Programming

Tip 1: Using the "rdtsc" with "gcc



1. Using the "rdtsc" with "gcc"

Tip 2: Python syntax error at colon in a dictonary



Consider the following simple python program to create a dictionary and print it.



The above program will throw the error



For a python beginner immedieately spotting the error might be difficult. All we have missed in the above program is a the "," after "x":1. Add the command the program should compile and run.

Tip 3: Finding unique elements of a list



Given a python list, we can pring the unique elements in the list using the following program.



Tip 4: ValueError: cannot select an axis to squeeze out which has size not equal to one



The error is thrown by np.squeeze when the numpy array that is being passed to the squeeze function does not have any dimension equal to 1, which is what is required for the squeeze command to work. So print the shape of the numpy array to find what is the error. Example:

Tip 5: module 'scipy.misc' has no attribute 'imresize'



The above error is becasuse a number of functions have been depricated in the newer version of scipy and the alternative for these is to use skimage.transform. For example if you want to resize the image, import resize using

Now the resize function can be called directly and the image and the new size required can be passed to it. You can refer to the documentation fo skimage here

Tip 6:Scatter plot 'c' argument has .. elements,which is not acceptable for use with 'x' with size .., 'y' with size ...



The above error might come when the argument 'c' passed to the scatter call is not a one dimentional array or if the size required for 'c' does not match with that passed to x and y. One way to work around if you are passing a 2D or multidimentional array to 'c' is to ravel it before assinging it to c.



This could be one possible solution.