# Nolan's Notes

### Site Tools

programming:scientific

# Scientific Programming

## Speed Testing

• http://www.scipy.org/PerformancePython. Numpy is about the same speed as Matlab (both 50X faster than just Python), and about a 10X speedup is gained by going to some form of C++ (good examples in the document)

## Matlab

• Matlab looks great for analyzing files quickly, code is quite efficient character-wise for prototyping, but not really for long-term usage apparently.
• Costs a lot of money (\$5000+) once you get to industry and is a lot of headache to deal with license server and stuff

## Python

Another great option is the scientific toolboxes in Python.

• See top link for great Python tutorial
• Python(x,y) is the best to start with. Includes most packages you need
• DIVISION IN PYTHON TAKES FLOOR
• In Python 3.0, integer division will return a float, e.g., 1/3 will be 0.3333… At Scipy 2006, Guido explicitly stated in his keynote talk that the design choice he made in Python (i.e., that n/m is floor(n/m)) was a mistake.
• In Sage (http://sagemath.org), which is built on Python, we do some very minimal preparsing of input, so that 1/3 is the exact rational number 1/3 (instead of Python's stupid 1/3 == 0). We also replace, e.g., 2^3 by 23. Sage is does a lot of exact symbolic and high precision arithmetic, so 1/3 staying the rational 1/3 makes sense as the default (though one can easily change this).
• Print out stack (useful for try / except stuff): `traceback.print_exc()`

#### Vanilla

##### Ranking
```# By Peter Norvig
ranks = ['--23456789TJQKA'.index(r) for r,c in hand] #outputs index of char...nice```

#### Numpy

##### Appending
```list = []
for i in range(10):
list.append([i,i+1])
numpy.concatenate(tuple(self.dict[key]), axis=0)```

#### Fast File Importing

```#Gather all the elements returning from the generator
big_list = list(the_generator)```

## The Verdict

```I use matlab for offline analysis and python for on the fly processing <and GUIs, and end products>.
Matlab is more complete but heavier.
Python is open source and faster.

I use both, for different purposes.``` 