Matthew - are you sure your arrays are of type boolean?  If I try to create
an array equivalent to one of yours this way:

   mx=. 1-?484 200000$2
|out of memory
| mx=.1 -?484 200000$2

I run out of memory because, even though "mx" will be all ones and zeros,
they will be integers because they are the result of an integer function.

On the other hand, I have no problem creating this:

   mx=. -.?484 200000$2

which we can see is type boolean:

   3!:0 mx
1

as opposed to this (note the reduction in size to avoid running out of
memory):

   mx=. 1-?484 20000$2
   3!:0 mx
4

which is integer.  You can coerce an array of ones and zeros to boolean like
this:

   3!:0 mx  NB. is now integer
4
   ~.,mx   NB. Is only zeros and ones
0 1
   mx=. 1=mx
   3!:0 mx   NB. is now boolean
1

Hope this helps,

Devon



On 7/22/08, Matthew Brand <[EMAIL PROTECTED]> wrote:
>
> Hi All,
>
> I am writing a program to generate two dimensional histograms but find that
> the "out of memory" error is generated for reasonable sized datasets. So
> far
> I have come up with the code below.
>
> Is there an alternative to *. which would avoid the out of memory error
> without doing an explicit
> for loop? Would the problem be solved by using J64?
>
> I just want to "and" each corresponding atom like in the following:
>
>    $mx
> 484 200000
>    $my
> 484 200000
>    mx*.my
> |out of memory
> |   mx    *.my
>
> Also, how can I add x and y labels to the output of viewmat?
>
> Thanks,
> Matthew.
>
> load 'viewmat'
> histogram2D =: 4 : 0 "_ 2
>   bx  =.  (__ , ( 0{::x )) ,. _ ,~ ( 0{::x )    NB. cut boundaries
>   by  =.  (__ , ( 1{::x )) ,. _ ,~ ( 1{::x )    NB. cut boundaries
>   b =. _4 ]\  , bx ,"_1 _"_ _1 by          NB. corners of grid boxes
>   lbx =. ([: 0&{ [)            NB. verb to get lower bound from the pair of
> bounds
>   ubx =. ([: 1&{ [)             NB. verb to get upper bound from the pair
> of
> bounds
>   lby =. ([: 2&{ [)            NB. verb to get lower bound from the pair of
> bounds
>   uby =. ([: 3&{ [)             NB. verb to get upper bound from the pair
> of
> bounds
>     mx =. b ( (] >: lbx ) *. ( ] < ubx) )"1 1 ( 0 {"1 y )  NB. mask for
> datapoints in each boundaries
>   my =. b ( (] >: lby ) *. ( ] < uby) )"1 1 ( 1 {"1 y ) NB. mask for
> datapoints in each boundaries
>   m =. mx *. my           NB. each point is in one and only one box
>   hz =.  (- # by ) ]\ ( [: (] % +/) +/"1 ) m
>   hx =. (2: %~ lbx + ubx)"1 b
>   hy =. (2: %~ lby + uby)"1 b
>   viewmat hz
>   hx;hy;hz
> )
> NB. example
> ((steps _4 4 20);(steps _4 4 20))histogram2D (((normalrand
> 100000),.(normalrand 100000)),.1)
> NB. but this runs out of memory on line "m =. mx *. my "
> ((steps _4 4 20);(steps _4 4 20))histogram2D (((normalrand
> 200000),.(normalrand 200000)),.1)
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



-- 
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to