Why does that happen?

— Keeping track of things I should remember



  1. Find a Value in a C++ Vector

    To search for a value in a vector we can use find, which returns an iterator pointing to the first value found in a vector which matches the value passed in. If an item is not in a vector, the returned iterator points to one past the end of the vector, myVec.end(). …


  2. Erasing a value from a vector in C++

    To remove a value from a vector we must follow the erase-remove idiom, the first step is to find the value that we wish to remove and move it to the front of the container. This is performed using remove which returns an iterator pointing to the new end of the vector, effectively ignoring the removed values. For example: …


  3. C++ Maps

    Maps can be used in C++ to store data in key, value pairs which can then be indexed by the key. Initialize a map as follows: …


  4. Sorting numpy arrays by index

    I have 2 1D numpy arrays of the same dimension, a and b, and I want to sort the arrays using the values in b. This can be achieved with lists as outlined in this previous post or by using numpy’s argsort. …


  5. Upgrading Python Packages on Windows

    Today I decided to install openCV to explore some image processing stuff I had been thinking about. This required that I upgrade my numpy install to a newer version. Windows is an awful environment to do things like this, so here is a guide to save myself the pain the next time I have to do this. …


  6. Using gdb To Debug C++

    When trying to find the precise point in your code that causes a crash, it is often useful to use gdb to debug the code. I always forget the basic syntax to get it running so here is a very simple overview. This is by no means exhaustive, but should serve as a jumping off point for using gdb. …


  7. Reading Data From Files with C++

    I want to read some data from a text file of unknown length using C++. If the file is space delimited this is quite easy. I can use infile to break each line up into tokens divided by the spaces and then load them into temp variables. …


  8. Getting a Random Sample From an Array

    I wanted to quickly grab a random sample of values from a larger array to perform some testing. I didn’t need to worry about the distribution of the sampled data: I just needed n values drawn at random from the array. I used shuffle from numpy.random to randomise the values in my input array. shuffle operates in place, so I made a copy of the array to avoid future problems. I can then simply take a slice of the first n values in the array, which will be a random selection of n values drawn from the original data: …


  9. Sorting a List by Another List

    I have 3 python lists of the same dimensions, a, b and c and I want to reorder them all based on the values in b. First create some toy data: …


  10. Renewing a Kerberos Ticket

    To get a new ticket while connected via ssh to a server, type kinit and then your password at the prompt. …