2

I am new to PDL and please forgive my rudimentary question:

I have two simple pdl objects

pdl> p $a                                                                                                                    

[
  [1 2 3]
  [4 5 6]
]

pdl> p $c                                                                                                                    
[6 6 6]

I glue them together and return what I expect

pdl> p glue $b, $c                                                                                                           

 [
  [1 2 3]
  [4 5 6]
 ]
 [6 6 6]

However, when I assign the glue to a variable $z the glue doesn't stick.

 $z = glue $b, $c  


 pdl> p $z                                                                                                                    

 [
  [1 2 3]
  [4 5 6]
 ]

What am I missing?

My ultimate goal is to build a large piddle by looping through a file using glue, cat or append.

  • 1
    First, for your actual use case, would rcols solve your problem? Second, it will be faster (and likely be clearer to other Perl programmers) if you build an array of piddles, like `push @piddle_lines, $piddle_of_line`, and then cat them all together at the end: `$data_piddle = cat(@piddle_lines)`. – David Mertens Feb 13 '12 at 20:25
  • 1
    You can search and display the PDL documentation from either the `perldl` or `pdl2` shells using the `help` or `apropos` commands. These can be abbreviated by `?` or `??' respectively. E.g., `help glue` would give you the documentation for `glue`. – chm Apr 24 '12 at 14:05

1 Answers1

4

That's not how you use glue(). From the docs:

$c = $a->glue(<dim>,$b,...)

I believe you would have to do something like $z = $b->glue(1,$c). I'm a little unsure about the <dim> parameter though; try playing around with it and see what happens.

Edit: Yeah, you would use a <dim> of 1:

pdl> $a = pdl [[1,2,3],[4,5,6]];

pdl> p $a

[
 [1 2 3]
 [4 5 6]
]

pdl> $c = pdl [6,6,6];

pdl> p $c
[6 6 6]
pdl> $z = $a->glue(1,$c);

pdl> p $z

[
 [1 2 3]
 [4 5 6]
 [6 6 6]
]
daxim
  • 39,270
  • 4
  • 65
  • 132
CanSpice
  • 34,814
  • 10
  • 72
  • 86