[Jprogramming] Scalar to Vector - Yet again
Raul Miller
rauldmiller at gmail.com
Tue Sep 4 20:48:41 UTC 2012
Here's a misguided implementation of singleton extension in J:
flattensingles=: ,/^:(1 +/@(*/\) .= $)
It works by removing any leading "1" dimensions:
$ flattensingles=: ,/^:(1 +/@(*/\) .= $) i. 1 1 2 3
2 3
So
A=:1 1$4
3 2 +&flattensingles A
7 6
The reason this is misguided is that sometimes you will want a leading
dimension of 1.
The right way to solve this problem is to not use leading dimensions
of 1 when you do not want them. (The computer cannot read your mind,
though, so this is best implemented in your data.)
--
Raul
More information about the Programming
mailing list