how to do numpy.fromstring in Go ?

264 views
Skip to first unread message

Christian LeMoussel

unread,
Dec 6, 2017, 1:38:44 PM12/6/17
to golang-nuts
I have to write a Python program that uses numpy in GO.
I have this Python code :
  prefix = "de98671db1ce0e5c9ba89ab7ccdca6c427460295b8dd3642e9b2bb961723307c57629b1ad37909a863a56965"
 
prefix_np = np.fromstring(prefix[0:64], dtype=np.uint32, count=16)
  print("prefix_np: {}".format(prefix_np))

Output :

prefix_np: [ 943285604 1680946998 1700999522 1664443696  945906233  929194297 1667523427  878917217  909391666  892940848 1684289634  842282547 845298021  909730402  858928945 1664561203]

Some idea how can I do this efficiently in GO ?
Is there a library equivalent to numpy in GO?


Thank you for your help
G
M
T
Fonction Sound est limitée à 200 caractères

Jonathan Yu

unread,
Dec 6, 2017, 2:03:57 PM12/6/17
to Christian LeMoussel, golang-nuts
2017-12-06 10:38 GMT-08:00 Christian LeMoussel <cnh...@gmail.com>:
I have to write a Python program that uses numpy in GO.
I have this Python code :
  prefix = "de98671db1ce0e5c9ba89ab7ccdca6c427460295b8dd3642e9b2bb961723307c57629b1ad37909a863a56965"
 
prefix_np = np.fromstring(prefix[0:64], dtype=np.uint32, count=16)
  print("prefix_np: {}".format(prefix_np))

Output :

prefix_np: [ 943285604 1680946998 1700999522 1664443696  945906233  929194297 1667523427  878917217  909391666  892940848 1684289634  842282547 845298021  909730402  858928945 1664561203]

Some idea how can I do this efficiently in GO ?

I guess this would depend on whether this is  a well-defined format; you might have to port numpy's fromstring to Go? But it should be possible... If you control the Python side, it might be easier to dump the data as JSON and import into Go that way.

Is there a library equivalent to numpy in GO?

I'm not knowledgeable enough to say, but Go has gonum which has similar goals to numpy and other data science toolkits: https://github.com/gonum/gonum 



Thank you for your help
G
M
T
Fonction Sound est limitée à 200 caractères

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jonathan Yu @jawnsy on LinkedInTwitterGitHubFacebook
“Ever tried. Ever failed. No matter. Try again. Fail again. Fail better.” — Samuel Beckett, Worstward Ho (1983) 

“In an adaptive environment, winning comes from adapting to change by continuously experimenting and identifying new options more quickly and economically than others. The classical strategist's mantra of sustainable competitive advantage becomes one of serial temporary advantage.” — Navigating the Dozens of Different Strategy Options (HBR)

Sebastien Binet

unread,
Dec 6, 2017, 2:14:12 PM12/6/17
to Jonathan Yu, Christian LeMoussel, golang-nuts
Here is how I would do it:
Reply all
Reply to author
Forward
0 new messages