1
# Copyright (C) 1998 Tuomas J. Lukka.
2
# All rights reserved, except redistribution
3
# with PDL under the PDL License permitted.
5
package PDL::Demos::General;
8
PDL::Demos::Routines->import();
16
Welcome to a short tour of PDL's capabilities.
18
This tour shows some of the main selling points
19
of PDL. However, because we want this script to
20
run everywhere, some modules which require external
21
modules for use are explicitly excluded, namely
22
- PDL::Graphics::TriD (3D Graphics) [*]
23
- PDL::Graphics::PGPLOT (PGPLOT graphics)
24
- PDL::IO::FlexRaw (flexible raw input/output)
25
[*]: this module has its separate demos in a subdirectory.
27
Note that your own scripts must start with
31
to work properly, so that you can simply say
35
or you can just try some of the commands illustrated
36
in the demos by just retyping them at the perldl
41
$a = zeroes 5,5; # 5x5 matrix
46
# Now, don't think that the number of dimensions is limited
48
$m = zeroes(3,2,2); # 3x2x2 cube
53
$a ++; # Operators like increment work..
58
# xvals and yvals (yes, there is also zvals...)
59
# give you piddles which give the coordinate value.
65
# So you can do things like
66
$b = $a + 0.1 * xvals($a) + 0.01 * yvals($a);
71
# Arithmetic operations work:
74
output ((sin $x),"\n");
78
# You can also take slices:
80
output $b->slice(":,2:3"); # rows 2 and 3
83
output $b->slice("2:3,:"); # or columns 2 and 3
88
output $b->diagonal(0,1),"\n"; # 0 and 1 are the dimensions
92
# One of the really nifty features is that the
93
# slices are actually references back to the original
95
$diag = $b->diagonal(0,1);
101
output "Now, guess what \$b looks like?\n";
105
# Yes, it has changed:
110
# Another example (we only modify elements 0,2 and 4 of
112
$t = $b->slice("0:4:2"); $t += 50;
117
# There are lots of useful functions in e.g. PDL::Primitive
118
# and PDL::Slices - we can't show you all but here are some
122
output $b->sum, "\n";
123
output $b->sumover,"\n"; # Only over first dim.
127
output $b->xchg(0,1);
128
output $b->minimum,"\n"; # over first dim.
137
# Here are some more advanced tricks for selecting
138
# parts of 1-D vectors:
140
$i = which(sin($a) > 0.5); # Indices of those sines > 0.5
143
output $a->index($i),"\n";
144
# and we can have the effect of the last command in one
145
# go using 'where' instead of 'which' and 'index' as in
146
output $a->where(sin($a) > 0.5),"\n";
147
# and finally take the sin of these elements
148
# (to show that these are indeed the correct ones)
149
output sin($a->index($i)),"\n";
153
We hope you enjoyed these demos illustrating some
154
of the basic capabilities of PDL.
156
We encourage you to play with these commands in
157
the perldl shell and use its online help support
158
to find out more about these and other commands and
161
Just type 'help' to get started.