chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] array-lib : prepending unit axes


From: Terrence Brannon
Subject: [Chicken-users] array-lib : prepending unit axes
Date: Sun, 4 Nov 2007 18:41:32 -0500

i wrote a function to prepend unit axes onto an array. this is
oftentimes necessary to get arrays to the same rank before applying
some sort of operation to them.

if there is a better way to do this, I'm all ears. Please, no comments
about my parenthesizing style :)

(define prepend-unit-axes
  (lambda (n a)
    (if (<= n 0)
        a
        (let* (
               [ones (make-list n 1)]
               [new-dim (flatten ones (array-dimensions a))]
               [as-v (array->vector a)]
               [as-l (vector->list as-v)]
               )
          (apply array '#() new-dim as-l)))))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]