![]() |
Blitz Support : |
From: Julian C. Cummings (cummings_at_[hidden])
Date: 2004-08-05 14:43:05
> > Hi there:
> >
> > I want to know if I can do some simple Matlab stuff with blitz like
> > these Matlab examples,
> >
> > N = 10000;
> > A = [7:N]; % create a length N-6 array
> >
> > How do you do it in blitz?
> This one is easy:
>
> int N = 10000;
> Array<float,1> A(Range(1,N-6));
> A = tensor::i+6;
I just want to point out that you only need the Range object here to force
the Array element numbering to begin with 1. If you are happy with the
default zero-based indexing, you could write
Array<float,1> A(N-6);
A = tensor::i + 7;
> >Then there's this example,
> >
> >M = [1:4; 5:8; 9:12]
> >M =
> > 1 2 3 4
> > 5 6 7 8
> > 9 10 11 12
>
> I would do this one as follows:
> Array<float,2> M(Range(1,3),Range(1,4));
> M = 4*(tensor::i-1)+tensor::j;
Perhaps a more convenient way to do this for small arrays like this one is
to use the ListInitialization capability of blitz. Instead of the tensor
expression, just write
M = 1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12;
The default Array storage in blitz is C style, so this will initialize along
each row.
> >M(1,1:3) = [3:-1:1]
> >M =
> > 3 2 1 4
> > 5 6 7 8
> > 9 10 11 12
>
> I am not sure about this one, perhaps someone with more
> experience in blitz can help? I would just use the same
> method as above and then change the first row by hand.
The blitz Arrays support slicing notation just like Matlab. So you can say
M(1,Range(1,3)) = 4 - tensor::i;
The tensor::i may seem a bit confusing here, but because you are reducing
the dimensionality of the array on the left-hand side of the expression to a
1d slice, you would use the first dimension placeholder tensor::i here.
Otherwise, you can once again use the ListInitialization approach:
M(1,Range(1,3)) = 3, 2, 1;
Regards, Julian C.
Dr. Julian C. Cummings
Staff Scientist, CACR/Caltech
(626) 395-2543
cummings_at_[hidden]