Did you try |: with boxed x?
(<0 1) |: i. 4 4
0 5 10 15
Henry Rich
On 11/18/2012 8:51 PM, Don & Cathy Kelly wrote:
This also helped me where I wanted to extract the diagonal elements of
an array!
I was trying for a neater way to do it but as in the end, I have to do
it several times, it appears that it is easier to establish a unit
matrix and then use this each time I want to deal with a matrix of the
same size
rather than using (* =@i.@#) y and repeating for different y or using
the cap as you suggest, I can simply define a unit matrix U
and then us U*y as needed.
Still very hit and miss on the multiple ways to skin a cat in J
Don Kelly
On 15/11/2012 9:55 PM, bob therriault wrote:
Hey Vijay,
Nothing wrong with a novice question, especially when it is so clearly
phrased.
Take a look at these examples and see if this gives you some ideas.
fact1=: */@:>:@:i.
fact1 5
120
fact2=: [:*/>:@:i.
fact2 5
120
fact3=: [:*/[:>:i.
fact3 5
120
You want to have the verbs act sequentially on the argument and your
original definition is a fork which has the outside verbs act on the
argument and then send the results to the left and the right of the
centre verb.
(v1 v2 v3) y is actually ((v1 y) v2 (v3 y)). In this case (*/ >: i.) 5
becomes ((*/ 5) >: (i. 5)) and then (5 >: 0 1 2 3 4) which becomes 1 1
1 1 1
A good reference link would be
http://www.jsoftware.com/jwiki/Guides/Language%20FAQ#Guides.2FLanguage_FAQ.2FSentence_Train.Why_.2B-.2F_.2A:_a_works.2C_but_when_I_say_foo_.3D:_.2B-.2F_.2A:.2C_foo_a_doesn.27t_work.3F
Hope this helps. There is a lot to this language, even when you have
been playing with it for a while, so keep at it.
Cheers, bob
On 2012-11-15, at 9:20 PM, Vijay Lulla wrote:
Please forgive me for asking a novice question.
I tried
*/>:i.5 NB. results in 120
But I define
fact=: */>:i.
fact 5 NB. results in 1 1 1 1 1
I remember reading about this somewhere but I cannot seem to find the
relevant pages now. Any pointers as to where I could find these
documents
or a brief explanation (which can be easily remembered) will be very
helpful and is highly appreciated.
Thanks,
Vijay Lulla.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm