44 function gtag ( ) { dataLayer . push ( arguments ) ; }
55 gtag ( 'js' , new Date ( ) ) ;
66
7- gtag ( 'config' , 'G-LN7PG6FJ2D' ) ; </ script > < link rel ="stylesheet " type ="text/css " href ="css/default.css " /> < link rel ="stylesheet " type ="text/css " href ="highlight/solarized-light.css " /> < script type ="text/javascript " src ="highlight/highlight.min.js "> </ script > < script type ="text/javascript " src ="js/jquery.min.js "> </ script > < script type ="text/javascript " src ="js/page_effects.js "> </ script > < script > hljs . initHighlightingOnLoad ( ) ; </ script > </ head > < body > < div id ="header "> < h2 > Generated by < a href ="https://github.com/weavejester/codox "> Codox</ a > with < a href ="https://github.com/xsc/codox-theme-rdash "> RDash UI</ a > theme</ h2 > < h1 > < a href ="index.html "> < span class ="project-title "> < span class ="project-name "> libpython-clj</ span > < span class ="project-version "> 2.019-SNAPSHOT</ span > </ span > </ a > </ h1 > </ div > < div class ="sidebar primary "> < h3 class ="no-link "> < span class ="inner "> Project</ span > </ h3 > < ul class ="index-link "> < li class ="depth-1 "> < a href ="index.html "> < div class ="inner "> Index</ div > </ a > </ li > </ ul > < h3 class ="no-link "> < span class ="inner "> Topics</ span > </ h3 > < ul > < li class ="depth-1 current "> < a href ="Usage.html "> < div class ="inner "> < span > LibPython-CLJ Usage</ span > </ div > </ a > </ li > < li class ="depth-1 "> < a href ="embedded.html "> < div class ="inner "> < span > Embedding Clojure In Python</ span > </ div > </ a > </ li > < li class ="depth-1 "> < a href ="environments.html "> < div class ="inner "> < span > Python Environments</ span > </ div > </ a > </ li > < li class ="depth-1 "> < a href ="new-to-clojure.html "> < div class ="inner "> < span > So Many Parenthesis!</ span > </ div > </ a > </ li > < li class ="depth-1 "> < a href ="scopes-and-gc.html "> < div class ="inner "> < span > Scopes And Garbage Collection</ span > </ div > </ a > </ li > < li class ="depth-1 "> < a href ="slicing.html "> < div class ="inner "> < span > Slicing And Slices</ span > </ div > </ a > </ li > </ ul > < h3 class ="no-link "> < span class ="inner "> Namespaces</ span > </ h3 > < ul > < li class ="depth-1 "> < div class ="no-link "> < div class ="inner "> < span class ="tree "> < span class ="top "> </ span > < span class ="bottom "> </ span > </ span > < span > libpython-clj2</ span > </ div > </ div > </ li > < li class ="depth-2 branch "> < a href ="libpython-clj2.codegen.html "> < div class ="inner "> < span class ="tree "> < span class ="top "> </ span > < span class ="bottom "> </ span > </ span > < span > codegen</ span > </ div > </ a > </ li > < li class ="depth-2 branch "> < a href ="libpython-clj2.embedded.html "> < div class ="inner "> < span class ="tree "> < span class ="top "> </ span > < span class ="bottom "> </ span > </ span > < span > embedded</ span > </ div > </ a > </ li > < li class ="depth-2 branch "> < a href ="libpython-clj2.java-api.html "> < div class ="inner "> < span class ="tree "> < span class ="top "> </ span > < span class ="bottom "> </ span > </ span > < span > java-api</ span > </ div > </ a > </ li > < li class ="depth-2 "> < a href ="libpython-clj2.python.html "> < div class ="inner "> < span class ="tree "> < span class ="top "> </ span > < span class ="bottom "> </ span > </ span > < span > python</ span > </ div > </ a > </ li > < li class ="depth-3 "> < a href ="libpython-clj2.python.np-array.html "> < div class ="inner "> < span class ="tree "> < span class ="top "> </ span > < span class ="bottom "> </ span > </ span > < span > np-array</ span > </ div > </ a > </ li > < li class ="depth-2 "> < a href ="libpython-clj2.require.html "> < div class ="inner "> < span class ="tree " style ="top: -52px; "> < span class ="top " style ="height: 61px; "> </ span > < span class ="bottom "> </ span > </ span > < span > require</ span > </ div > </ a > </ li > </ ul > </ div > < div class ="document " id ="content "> < div class ="doc "> < div class ="markdown "> < h1 > LibPython-CLJ Usage</ h1 >
7+ gtag ( 'config' , 'G-LN7PG6FJ2D' ) ; </ script > < link rel ="stylesheet " type ="text/css " href ="css/default.css " /> < link rel ="stylesheet " type ="text/css " href ="highlight/solarized-light.css " /> < script type ="text/javascript " src ="highlight/highlight.min.js "> </ script > < script type ="text/javascript " src ="js/jquery.min.js "> </ script > < script type ="text/javascript " src ="js/page_effects.js "> </ script > < script > hljs . initHighlightingOnLoad ( ) ; </ script > </ head > < body > < div id ="header "> < h2 > Generated by < a href ="https://github.com/weavejester/codox "> Codox</ a > with < a href ="https://github.com/xsc/codox-theme-rdash "> RDash UI</ a > theme</ h2 > < h1 > < a href ="index.html "> < span class ="project-title "> < span class ="project-name "> libpython-clj</ span > < span class ="project-version "> 2.018</ span > </ span > </ a > </ h1 > </ div > < div class ="sidebar primary "> < h3 class ="no-link "> < span class ="inner "> Project</ span > </ h3 > < ul class ="index-link "> < li class ="depth-1 "> < a href ="index.html "> < div class ="inner "> Index</ div > </ a > </ li > </ ul > < h3 class ="no-link "> < span class ="inner "> Topics</ span > </ h3 > < ul > < li class ="depth-1 current "> < a href ="Usage.html "> < div class ="inner "> < span > LibPython-CLJ Usage</ span > </ div > </ a > </ li > < li class ="depth-1 "> < a href ="embedded.html "> < div class ="inner "> < span > Embedding Clojure In Python</ span > </ div > </ a > </ li > < li class ="depth-1 "> < a href ="environments.html "> < div class ="inner "> < span > Python Environments</ span > </ div > </ a > </ li > < li class ="depth-1 "> < a href ="new-to-clojure.html "> < div class ="inner "> < span > So Many Parenthesis!</ span > </ div > </ a > </ li > < li class ="depth-1 "> < a href ="scopes-and-gc.html "> < div class ="inner "> < span > Scopes And Garbage Collection</ span > </ div > </ a > </ li > < li class ="depth-1 "> < a href ="slicing.html "> < div class ="inner "> < span > Slicing And Slices</ span > </ div > </ a > </ li > </ ul > < h3 class ="no-link "> < span class ="inner "> Namespaces</ span > </ h3 > < ul > < li class ="depth-1 "> < div class ="no-link "> < div class ="inner "> < span class ="tree "> < span class ="top "> </ span > < span class ="bottom "> </ span > </ span > < span > libpython-clj2</ span > </ div > </ div > </ li > < li class ="depth-2 branch "> < a href ="libpython-clj2.codegen.html "> < div class ="inner "> < span class ="tree "> < span class ="top "> </ span > < span class ="bottom "> </ span > </ span > < span > codegen</ span > </ div > </ a > </ li > < li class ="depth-2 branch "> < a href ="libpython-clj2.embedded.html "> < div class ="inner "> < span class ="tree "> < span class ="top "> </ span > < span class ="bottom "> </ span > </ span > < span > embedded</ span > </ div > </ a > </ li > < li class ="depth-2 branch "> < a href ="libpython-clj2.java-api.html "> < div class ="inner "> < span class ="tree "> < span class ="top "> </ span > < span class ="bottom "> </ span > </ span > < span > java-api</ span > </ div > </ a > </ li > < li class ="depth-2 "> < a href ="libpython-clj2.python.html "> < div class ="inner "> < span class ="tree "> < span class ="top "> </ span > < span class ="bottom "> </ span > </ span > < span > python</ span > </ div > </ a > </ li > < li class ="depth-3 "> < a href ="libpython-clj2.python.np-array.html "> < div class ="inner "> < span class ="tree "> < span class ="top "> </ span > < span class ="bottom "> </ span > </ span > < span > np-array</ span > </ div > </ a > </ li > < li class ="depth-2 "> < a href ="libpython-clj2.require.html "> < div class ="inner "> < span class ="tree " style ="top: -52px; "> < span class ="top " style ="height: 61px; "> </ span > < span class ="bottom "> </ span > </ span > < span > require</ span > </ div > </ a > </ li > </ ul > </ div > < div class ="document " id ="content "> < div class ="doc "> < div class ="markdown "> < h1 > LibPython-CLJ Usage</ h1 >
88< p > Python objects are essentially two dictionaries, one for 'attributes' and one for
99'items'. When you use python and use the '.' operator, you are referencing attributes.
1010If you use the '[]' operator, then you are referencing items. Attributes are built in,
@@ -26,17 +26,18 @@ <h4>Ubuntu</h4>
2626< h4 > MacOSX</ h4 >
2727< p > Python installation instructions < a href ="https://docs.python-guide.org/starting/install3/osx/ "> here</ a > .</ p >
2828< h3 > Initialize python</ h3 >
29- < pre > < code class ="language-clojure "> user>
29+ < pre > < code class ="language-clojure "> user> (require '[libpython-clj2.python
30+ :refer [as-python as-jvm
31+ ->python ->jvm
32+ get-attr call-attr call-attr-kw
33+ get-item initialize!
34+ run-simple-string
35+ add-module module-dict
36+ import-module
37+ python-type
38+ dir]
39+ :as py])
3040
31- user> (require [libpython-clj2.python
32- :refer [as-python as-jvm
33- ->python ->jvm
34- get-attr call-attr call-attr-kw
35- get-item initialize!
36- run-simple-string
37- add-module module-dict
38- import-module
39- python-type]])
4041nil
4142
4243; Mac and Linux
@@ -131,68 +132,34 @@ <h3>Execute Some Python</h3>
131132user> (vec (get-attr ones-ary "shape"))
132133[2 3]
133134
134- user> (att-type-map ones-ary)
135- {"T" :ndarray,
136- "__abs__" :method-wrapper,
137- "__add__" :method-wrapper,
138- "__and__" :method-wrapper,
139- "__array__" :builtin-function-or-method,
140- "__array_finalize__" :none-type,
141- "__array_function__" :builtin-function-or-method,
142- "__array_interface__" :dict,
143- "__array_prepare__" :builtin-function-or-method,
144- "__array_priority__" :float,
145- "__array_struct__" :py-capsule,
146- "__array_ufunc__" :builtin-function-or-method,
147- "__array_wrap__" :builtin-function-or-method,
148- "__bool__" :method-wrapper,
149- "__class__" :type,
150- "__complex__" :builtin-function-or-method,
151- "__contains__" :method-wrapper,
135+ user> (dir ones-ary)
136+ ["T"
137+ "__abs__"
138+ "__add__"
139+ "__and__"
140+ "__array__"
141+ "__array_finalize__"
152142 ...
153- "std" :builtin-function-or-method,
154- "strides" :tuple,
155- "sum" :builtin-function-or-method,
156- "swapaxes" :builtin-function-or-method,
157- "take" :builtin-function-or-method,
158- "tobytes" :builtin-function-or-method,
159- "tofile" :builtin-function-or-method,
160- "tolist" :builtin-function-or-method,
161- "tostring" :builtin-function-or-method,
162- "trace" :builtin-function-or-method,
163- "transpose" :builtin-function-or-method,
164- "var" :builtin-function-or-method,
165- "view" :builtin-function-or-method}
166- </ code > </ pre >
167- < h3 > att-type-map</ h3 >
168- < p > It can be extremely helpful to print out the attribute name->attribute type map:</ p >
169- < pre > < code class ="language-clojure "> user> (att-type-map ones-ary)
170- {"T" :ndarray,
171- "__abs__" :method-wrapper,
172- "__add__" :method-wrapper,
173- "__and__" :method-wrapper,
174- "__array__" :builtin-function-or-method,
175- "__array_finalize__" :none-type,
176- "__array_function__" :builtin-function-or-method,
177- "__array_interface__" :dict,
178- ...
179- "real" :ndarray,
180- "repeat" :builtin-function-or-method,
181- "reshape" :builtin-function-or-method,
182- "resize" :builtin-function-or-method,
183- "round" :builtin-function-or-method,
184- "searchsorted" :builtin-function-or-method,
185- "setfield" :builtin-function-or-method,
186- "setflags" :builtin-function-or-method,
187- "shape" :tuple,
188- "size" :int,
189- "sort" :builtin-function-or-method,
190143 ...
191- }
192- </ code > </ pre >
193- < h3 > DataFrame access full example</ h3 >
194- < p > Here's how to create Pandas DataFrame and accessing its rows via < code > loc</ code > in both Python and Clojure:</ p >
195- < pre > < code class ="language-python "> # Python
144+ "strides"
145+ "sum"
146+ "swapaxes"
147+ "take"
148+ "tobytes"
149+ "tofile"
150+ "tolist"
151+ "tostring"
152+ "trace"
153+ "transpose"
154+ "var"
155+ "view"]
156+
157+ ### DataFrame access full example
158+
159+ Here's how to create Pandas DataFrame and accessing its rows via `loc` in both Python and Clojure:
160+
161+ ```python
162+ # Python
196163import numpy as np
197164import pandas as pan
198165
@@ -202,6 +169,7 @@ <h3>DataFrame access full example</h3>
202169table.loc[row_date]
203170</ code > </ pre >
204171< pre > < code class ="language-clojure "> ; Clojure
172+ (require '[libpython-clj2.require :refer [require-python]])
205173(require-python '[numpy :as np])
206174(require-python '[pandas :as pan])
207175
@@ -255,7 +223,7 @@ <h4>Experimental Sugar</h4>
255223user> (py/$.. numpy random shuffle)
256224<built-in method shuffle of numpy.random.mtrand.RandomState object at 0x7fa66410cca8>
257225</ code > </ pre >
258- < h5 > New sugar (fixme) </ h5 >
226+ < h5 > Extra sugar</ h5 >
259227< p > < code > libpython-clj</ code > offers syntactic forms similar to those offered by
260228Clojure for interacting with Python classes and objects.</ p >
261229< p > < strong > Class/object methods</ strong >
@@ -276,9 +244,9 @@ <h5>New sugar (fixme)</h5>
276244</ code > </ pre >
277245< p > (< strong > Note</ strong > : requires Python < code > requests</ code > module installled)</ p >
278246< p > < strong > Examples</ strong > </ p >
279- < pre > < code class ="language-clojure "> user=> (require '[libpython-clj .python :as py :refer [py. py.. py.-]])
247+ < pre > < code class ="language-clojure "> user=> (require '[libpython-clj2 .python :as py :refer [py. py.. py.-]])
280248nil
281- user=> (require '[libpython-clj .require :refer [require-python]])
249+ user=> (require '[libpython-clj2 .require :refer [require-python]])
282250
283251... debug info ...
284252
@@ -314,22 +282,26 @@ <h5>New sugar (fixme)</h5>
314282</ code > </ pre >
315283< h3 > Numpy</ h3 >
316284< p > Speaking of numpy, you can move data between numpy and java easily.</ p >
317- < pre > < code class ="language-clojure "> user> (def tens-data (as-tensor ones-ary))
285+ < pre > < code class ="language-clojure "> (require '[tech.v3.tensor :as dtt])
286+ ;;includes the appropriate protocols and multimethod overloads
287+ (require '[libpython-clj2.python.np-array]
288+ ;;python objects created now for numpy arrays will be different. So you have to require
289+ ;;np-array *before* you create your numpy data.
290+ user> (def ones-ary (py/py. np ones [2 3]))
291+ #'user/ones-ary
292+ user> (def tens-data (dtt/as-tensor ones-ary))
318293#'user/tens-data
319- user> (println tens-data)
320- #tech.v2 .tensor<float64>[2 3]
294+ user> tens-data
295+ #tech.v3 .tensor<float64>[2 3]
321296[[1.000 1.000 1.000]
322297 [1.000 1.000 1.000]]
323- nil
324298
325299
326- user> (require '[tech.v2 .datatype :as dtype])
300+ user> (require '[tech.v3 .datatype :as dtype])
327301nil
328- user> (def ignored (dtype/copy! (repeat 6 5) tens-data))
302+ ;;Only constant-time count items can be copied, so vectors and arrays and such.
303+ user> (def ignored (dtype/copy! (vec (repeat 6 5)) tens-data))
329304#'user/ignored
330- user> (.put main-globals "ones_ary" ones_ary)
331- Syntax error compiling at (*cider-repl cnuernber/libpython-clj:localhost:39019(clj)*:191:7).
332- Unable to resolve symbol: ones_ary in this context
333305user> (.put main-globals "ones_ary" ones-ary)
334306nil
335307
0 commit comments