@@ -36,19 +36,19 @@ Python installation instructions [here](https://docs.python-guide.org/starting/i
36
36
37
37
38
38
### Initialize python
39
-
40
39
``` clojure
41
- user>
40
+ user> (require '[libpython-clj2.python
41
+ :refer [as-python as-jvm
42
+ ->python ->jvm
43
+ get-attr call-attr call-attr-kw
44
+ get-item initialize!
45
+ run-simple-string
46
+ add-module module-dict
47
+ import-module
48
+ python-type
49
+ dir]
50
+ :as py])
42
51
43
- user> (require [libpython-clj2.python
44
- :refer [as-python as-jvm
45
- ->python ->jvm
46
- get-attr call-attr call-attr-kw
47
- get-item initialize!
48
- run-simple-string
49
- add-module module-dict
50
- import-module
51
- python-type]])
52
52
nil
53
53
54
54
; Mac and Linux
@@ -158,70 +158,27 @@ user> (get-attr ones-ary "shape")
158
158
user> (vec (get-attr ones-ary " shape" ))
159
159
[2 3 ]
160
160
161
- user> (att-type-map ones-ary)
162
- {" T" :ndarray ,
163
- " __abs__" :method-wrapper ,
164
- " __add__" :method-wrapper ,
165
- " __and__" :method-wrapper ,
166
- " __array__" :builtin-function-or-method ,
167
- " __array_finalize__" :none-type ,
168
- " __array_function__" :builtin-function-or-method ,
169
- " __array_interface__" :dict ,
170
- " __array_prepare__" :builtin-function-or-method ,
171
- " __array_priority__" :float ,
172
- " __array_struct__" :py-capsule ,
173
- " __array_ufunc__" :builtin-function-or-method ,
174
- " __array_wrap__" :builtin-function-or-method ,
175
- " __bool__" :method-wrapper ,
176
- " __class__" :type ,
177
- " __complex__" :builtin-function-or-method ,
178
- " __contains__" :method-wrapper ,
179
- ...
180
- " std" :builtin-function-or-method ,
181
- " strides" :tuple ,
182
- " sum" :builtin-function-or-method ,
183
- " swapaxes" :builtin-function-or-method ,
184
- " take" :builtin-function-or-method ,
185
- " tobytes" :builtin-function-or-method ,
186
- " tofile" :builtin-function-or-method ,
187
- " tolist" :builtin-function-or-method ,
188
- " tostring" :builtin-function-or-method ,
189
- " trace" :builtin-function-or-method ,
190
- " transpose" :builtin-function-or-method ,
191
- " var" :builtin-function-or-method ,
192
- " view" :builtin-function-or-method }
193
- ```
194
-
195
-
196
- ### att-type-map
197
-
198
- It can be extremely helpful to print out the attribute name->attribute type map:
199
-
200
- ``` clojure
201
- user> (att-type-map ones-ary)
202
- {" T" :ndarray ,
203
- " __abs__" :method-wrapper ,
204
- " __add__" :method-wrapper ,
205
- " __and__" :method-wrapper ,
206
- " __array__" :builtin-function-or-method ,
207
- " __array_finalize__" :none-type ,
208
- " __array_function__" :builtin-function-or-method ,
209
- " __array_interface__" :dict ,
161
+ user> (dir ones-ary)
162
+ [" T"
163
+ " __abs__"
164
+ " __add__"
165
+ " __and__"
166
+ " __array__"
167
+ " __array_finalize__"
210
168
...
211
- " real" :ndarray ,
212
- " repeat" :builtin-function-or-method ,
213
- " reshape" :builtin-function-or-method ,
214
- " resize" :builtin-function-or-method ,
215
- " round" :builtin-function-or-method ,
216
- " searchsorted" :builtin-function-or-method ,
217
- " setfield" :builtin-function-or-method ,
218
- " setflags" :builtin-function-or-method ,
219
- " shape" :tuple ,
220
- " size" :int ,
221
- " sort" :builtin-function-or-method ,
222
169
...
223
- }
224
- ```
170
+ " strides"
171
+ " sum"
172
+ " swapaxes"
173
+ " take"
174
+ " tobytes"
175
+ " tofile"
176
+ " tolist"
177
+ " tostring"
178
+ " trace"
179
+ " transpose"
180
+ " var"
181
+ " view" ]
225
182
226
183
### DataFrame access full example
227
184
@@ -240,6 +197,7 @@ table.loc[row_date]
240
197
241
198
``` clojure
242
199
; Clojure
200
+ (require '[libpython-clj2.require :refer [require-python]])
243
201
(require-python '[numpy :as np])
244
202
(require-python '[pandas :as pan])
245
203
@@ -306,7 +264,7 @@ user> (py/$.. numpy random shuffle)
306
264
<built-in method shuffle of numpy.random.mtrand.RandomState object at 0x7fa66410cca8 >
307
265
```
308
266
309
- ##### New sugar ( fixme )
267
+ ##### Extra sugar
310
268
311
269
`libpython-clj` offers syntactic forms similar to those offered by
312
270
Clojure for interacting with Python classes and objects.
@@ -338,9 +296,9 @@ To achieve a chain of method/attribute access, use the `py..` for.
338
296
**Examples**
339
297
340
298
```clojure
341
- user=> (require '[libpython-clj .python :as py :refer [py. py.. py.-]])
299
+ user=> (require '[libpython-clj2 .python :as py :refer [py. py.. py.-]])
342
300
nil
343
- user=> (require '[libpython-clj .require :refer [require-python]])
301
+ user=> (require '[libpython-clj2 .require :refer [require-python]])
344
302
345
303
... debug info ...
346
304
@@ -382,6 +340,7 @@ user=> (py.. requests (get "http://www.google.com") -content (decode "latin-1"))
382
340
Speaking of numpy, you can move data between numpy and java easily.
383
341
384
342
```clojure
343
+ (require '[tech.v3.tensor :refer [as-tensor]])
385
344
user> (def tens-data (as-tensor ones-ary))
386
345
#'user/tens-data
387
346
user> (println tens-data)
@@ -391,7 +350,7 @@ user> (println tens-data)
391
350
nil
392
351
393
352
394
- user> (require '[tech.v2 .datatype :as dtype])
353
+ user> (require '[tech.v3 .datatype :as dtype])
395
354
nil
396
355
user> (def ignored (dtype/copy! (repeat 6 5 ) tens-data))
397
356
#'user/ignored
0 commit comments