Skip to content

Commit eebe879

Browse files
patstewtonyroberts
authored andcommitted
Create README.md
1 parent 0bd8c47 commit eebe879

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
pythonnet
2+
=========
3+
4+
This fork of http://sourceforge.net/projects/pythonnet/ allows easy calling of python functions from C#.
5+
6+
All calls to python should be inside a "using (Py.GIL()) {/* Your code here */}" block.
7+
Import python modules using dynamic mod = Py.Import("mod"), then you can call functions as normal, eg
8+
mod.func(args).
9+
Use mod.func(args, Py.kw("keywordargname", keywordargvalue)) to apply keyword arguments.
10+
All python objects should be declared as 'dynamic' type.
11+
Mathematical operations involving python and literal/managed types must have the python object first, eg np.pi*2 works, 2*np.pi doesn't.
12+
13+
EG:
14+
15+
static void Main(string[] args)
16+
{
17+
using (Py.GIL()) {
18+
dynamic np = Py.Import("numpy");
19+
dynamic sin = np.sin;
20+
Console.WriteLine(np.cos(np.pi*2));
21+
Console.WriteLine(sin(5));
22+
Console.WriteLine(np.cos(5) + sin(5));
23+
dynamic a = np.array(new List<float> { 1, 2, 3 };
24+
dynamic b = np.array(new List<float> { 6, 5, 4 }, Py.kw("dtype", np.int32));
25+
Console.WriteLine(a.dtype);
26+
Console.WriteLine(b.dtype);
27+
Console.WriteLine(a * b);
28+
Console.ReadKey();
29+
}
30+
}
31+
32+
which outputs:
33+
34+
1.0
35+
-0.958924274663
36+
-0.6752620892
37+
float64
38+
int32
39+
[ 6. 10. 12.]

0 commit comments

Comments
 (0)