caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Create Array of floats from string
@ 2017-04-26 10:48 Jon Kleiser
  2017-04-26 11:02 ` rixed
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Jon Kleiser @ 2017-04-26 10:48 UTC (permalink / raw)
  To: caml-list

Hi,

I am quite new to OCaml, and I am looking for the most efficient way to make an Array of floats from string. My solution this far looks like this, where dims is a global variable specifying the size of the Arrays (typically 300):

let make_vector vec_strings =
  let vec = Array.make !dims 0.0 in
  List.iteri (fun i str -> vec.(i) <- float_of_string str) vec_strings

let process_line line =
  let parts = Str.split (Str.regexp " ") line in
  make_vector (List.tl parts)	(* skipping first element which is not a float *)

/Jon

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-04-28 12:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-26 10:48 [Caml-list] Create Array of floats from string Jon Kleiser
2017-04-26 11:02 ` rixed
2017-04-26 13:36   ` Francois BERENGER
     [not found] ` <CAPFanBGh0q2AaF7ROWJJF81o=8+79sn-q4-CxqCKGQ__Oa5SEw@mail.gmail.com>
2017-04-26 14:05   ` Jon Kleiser
2017-04-26 15:26     ` Gabriel Scherer
2017-04-27 14:00       ` [Caml-list] Create Array of floats from string, surprise Jon Kleiser
2017-04-26 15:27 ` [Caml-list] Create Array of floats from string Alain Frisch
2017-04-27  8:36   ` Jon Kleiser
2017-04-27  9:15   ` Jon Kleiser
2017-04-28 12:19     ` Jon Kleiser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).