Python

Factorial and Log Factorial

Factorial: When you need to calculate n!, you have several solutions.  The "rush" solution: using a loop or a recursive function:  def factorial_for(n): r = 1 for i in range(2, n + 1): r *= i return(r) def factorial_rec(n): if n > 1: return(n * factorial_rec(n - 1)) else: return(1) Here, the multiplication of the numbers sequentially will create a huge number very quickly. This is good, but computers are faster when 2 small numbers (120x30240) are involved in a multiplication versus the [...]

By |2017-04-29T15:33:07+00:00February 22, 2016|Categories: Performance, Python|Tags: |0 Comments

Generating Synthetic Genomic Data

Applying statistical methods is a large part of the work of a bioinformatician. Apart from some more classical techniques, machine learning algorithms are also regularly applied to clinical and biological data (notably, clustering techniques such as k-means). Some techniques such as artificial neural networks have recently found great success in areas such as image recognition and natural language processing. However, these techniques do not perform as well on small datasets with high dimensionality, a problem known as "the curse of dimensionality". [...]

By |2017-04-29T23:00:58+00:00January 7, 2016|Categories: Bioinformatics, Python|Tags: , |0 Comments

[Python] Iterators vs Generators

In Python, there are iterators and generators. You probably already use iterators without even knowing that you do so. But understanding the difference between those two concepts is really important since choosing one over the other has a huge impact on memory usage. If you are working with small datasets, memory usage might not be your first concern. However, with big datasets, it is another story. So what are they exactly, iterators and generators? Iterators The process of going through [...]

By |2017-04-29T15:37:35+00:00September 18, 2015|Categories: Performance, Python|0 Comments

Mutable Default Arguments in Python

A member of the platform recently stumbled upon a bug in his python code. Once we got to the bottom of it, we were surprised to find that the bug in question had been caused by a peculiar behavior of Python. Let's take the following code as example : def foo(bar=[]):     bar.append('a') return bar Intuitively, this piece of code might seem like it ought to return the list ['a'] whenever it is run. In practice, it is not quite so. >>>foo() [...]

By |2017-05-01T09:53:39+00:00August 7, 2015|Categories: Python|0 Comments

Put Those CPUs to Good Use !

If you're like me, you've probably noticed that, by default, the python scripts we write only use a portion of the processing power at our disposal.. As such, you've probably said to yourself: Hey, I paid good money for a quad-core CPU ! What's happening ? While it's true that nowadays, most CPUs are multi-core, the code we write must also be tailored appropriately in order to make use of more than one at a time. So let's dive into [...]

By |2017-04-24T13:28:50+00:00July 12, 2015|Categories: Performance, Python|Tags: |0 Comments
Go to Top