SERVING THE QUANTITATIVE FINANCE COMMUNITY

• 1
• 3
• 4
• 5
• 6
• 7
• 14

Cuchulainn
Posts: 59665
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

Be careful around the memory leaks in Pandas.
I suppose memory management in the Python-C twilight zone is tricky.
BTW library looks nice.

berndL
Posts: 171
Joined: August 22nd, 2007, 3:46 pm

### Re: Python tricks

1. I am looking for books on Numpy and Scipy, with focus on the numerical algorithms and background. I am not interested in having to wade in syntax before getting to these topics.

Any suggestions? Thx!
Not a book but maybe also interesting if you look at numpy. Take a look at cupy.

Lets you run the same code on either cpu or gpu by just setting a switch methode.

rmax
Posts: 6080
Joined: December 8th, 2005, 9:31 am

### Re: Python tricks

Cuchulainn
Posts: 59665
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

The Joy of FP
multiply = lambda x: x*x
add = lambda x: x+x
expo = lambda x: exp(x)

funcs = [multiply, add, expo]

input = [1,2,3,4]

for func in funcs:
value = list(map(func, a))
print(value)

for i in range(4):
values = map(lambda x: x(i), funcs)
print(values)



tagoma
Topic Author
Posts: 18255
Joined: February 21st, 2010, 12:58 pm

### Re: Python tricks

The Joy of FP
multiply = lambda x: x*x
add = lambda x: x+x
expo = lambda x: exp(x)

funcs = [multiply, add, expo]

input = [1,2,3,4]

for func in funcs:
value = list(map(func, a))
print(value)

for i in range(4):
values = map(lambda x: x(i), funcs)
print(values)



You probably need numpy or math (or cmath!?).
Variable a is not defined.
I would go for list comprehension. (sorry I previously typed in 'list a comprehension').

import numpy as np

multiply = lambda x: x*x
add = lambda x: x+x
expo = lambda x: np.exp(x)

funcs = [multiply, add, expo]

input = [1,2,3,4]

[list(map(func, input)) for func in funcs]
Last edited by tagoma on June 24th, 2019, 3:15 pm, edited 2 times in total.

Cuchulainn
Posts: 59665
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

Oh, a = [1,2,3]

BTW OOP in Python is a real shocker. Still, it is probably good for scaffolding to prevent cognitive overload?

Funny name, 'comprehension', C++ STL calls it 'transform' and more generic (ignore that remark).

ExSan
Posts: 4548
Joined: April 12th, 2003, 10:40 am

### Re: Python tricks

Oh, a = [1,2,3]

BTW OOP in Python is a real shocker. Still, it is probably good for scaffolding to prevent cognitive overload?

Funny name, 'comprehension', C++ STL calls it 'transform' and more generic (ignore that remark).
I spent some time trying to implement  abstract data structure Red-Black tree. I just gave up. It gets very complicated in python. Coding it using C/C++  is not easy, but a real nightmare in Python. My idea was to reproduce a master template I already coded in C

ISayMoo
Posts: 1988
Joined: September 30th, 2015, 8:30 pm

### Re: Python tricks

Cuchulainn
Posts: 59665
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

Cuchulainn
Posts: 59665
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

Python does not support private attributes/member data (?)

ExSan
Posts: 4548
Joined: April 12th, 2003, 10:40 am

### Re: Python tricks

Thanks!!! Now I have no excuses to retake my project!

FaridMoussaoui
Posts: 412
Joined: June 20th, 2008, 10:05 am
Location: Genève, Genf, Ginevra, Geneva

### Re: Python tricks

If you have a working library in C/C++, you can use it as a shared library in python through Boost.Python. No need to reinvent the wheel.

tagoma
Topic Author
Posts: 18255
Joined: February 21st, 2010, 12:58 pm

### Re: Python tricks

Python does not support private attributes/member data (?)
Not really (You already know it, don't you?).

https://docs.python.org/3.7/tutorial/classes.html#tut-private

Cuchulainn
Posts: 59665
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

If you have a working library in C/C++, you can use it as a shared library in python through Boost.Python. No need to reinvent the wheel.
Indeed.
Creating rb trees in Python must be the closest thing to torture.

Cuchulainn
Posts: 59665
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: Python tricks

Python does not support private attributes/member data (?)
Not really (You already know it, don't you?).

https://docs.python.org/3.7/tutorial/classes.html#tut-private
This is scary. Meshuggah.

It's just this subtle point will be lost on newbies going forward.
 ABOUT WILMOTT

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...

 JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...

GZIP: On