A vector to an array

This is a discussion on A vector to an array within the APL forums in Programming Languages category; Say you have a 100 element vector. You want to take that vector and duplicate it, say 20 times such that you get a 100 20 matrix where all 20 columns are identical. I know that you can just do: {transpose}20 100{rho}vector. I'm looking for other ways to accomplish the same thing in APL. Can you use an outer product or some other form of assignment? Thanks, Lance...

Go Back   Application Development Forum > Programming Languages > APL

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 12-17-2007, 11:53 AM
Lance
Guest
 
Default A vector to an array

Say you have a 100 element vector. You want to take that vector and
duplicate it, say 20 times such that you get a 100 20 matrix where all
20 columns are identical. I know that you can just do:

{transpose}20 100{rho}vector.

I'm looking for other ways to accomplish the same thing in APL. Can
you use an outer product or some other form of assignment?

Thanks,
Lance
Reply With Quote
  #2  
Old 12-17-2007, 12:20 PM
Phil Last
Guest
 
Default Re: A vector to an array

On Dec 17, 4:53 pm, Lance <Lanc...@gmail.com> wrote:
> Say you have a 100 element vector. You want to take that vector and
> duplicate it, say 20 times such that you get a 100 20 matrix where all
> 20 columns are identical. I know that you can just do:
>
> {transpose}20 100{rho}vector.
>
> I'm looking for other ways to accomplish the same thing in APL. Can
> you use an outer product or some other form of assignment?
>
> Thanks,
> Lance


vector∘.+20⍴0 ⍝ if it's numeric but don't bank on the efficiency!
Reply With Quote
  #3  
Old 12-17-2007, 12:22 PM
aleph0
Guest
 
Default Re: A vector to an array

Try ...

20/[1],[.1]VEC

This will replicate the first dimension 20 times to give you RHO = 20
100


20/,[1.1]VEC

This will replicate the second dimension 20 times to give you RHO =
100 20




On Dec 17, 5:53 pm, Lance <Lanc...@gmail.com> wrote:
> Say you have a 100 element vector. You want to take that vector and
> duplicate it, say 20 times such that you get a 100 20 matrix where all
> 20 columns are identical. I know that you can just do:
>
> {transpose}20 100{rho}vector.
>
> I'm looking for other ways to accomplish the same thing in APL. Can
> you use an outer product or some other form of assignment?
>
> Thanks,
> Lance


Reply With Quote
  #4  
Old 12-17-2007, 12:24 PM
Phil Last
Guest
 
Default Re: A vector to an array

On Dec 17, 5:20 pm, Phil Last <phil.l...@ntlworld.com> wrote:
> On Dec 17, 4:53 pm, Lance <Lanc...@gmail.com> wrote:
>
> > Say you have a 100 element vector. You want to take that vector and
> > duplicate it, say 20 times such that you get a 100 20 matrix where all
> > 20 columns are identical. I know that you can just do:

>
> > {transpose}20 100{rho}vector.

>
> > I'm looking for other ways to accomplish the same thing in APL. Can
> > you use an outer product or some other form of assignment?

>
> > Thanks,
> > Lance

>
> vector∘.+20⍴0 ⍝ if it's numeric but don't bank onthe efficiency!


vector∘.{⍺}20⍴0 ⍝ in Dyalog but with the same caution
Reply With Quote
  #5  
Old 12-17-2007, 12:38 PM
aleph0
Guest
 
Default Re: A vector to an array

>
> vector∘.{⍺}20⍴0 *⍝ in Dyalog but withthe same caution



Yep ..

A) VERY VERY slow compared the simple solution posted earlier
B) WS problems are imminent on larger "vector"s

;-)
Reply With Quote
  #6  
Old 12-17-2007, 01:24 PM
Ted Edwards
Guest
 
Default Re: A vector to an array

Lance wrote:
> Say you have a 100 element vector. You want to take that vector and
> duplicate it, say 20 times such that you get a 100 20 matrix where all
> 20 columns are identical. I know that you can just do:
>
> {transpose}20 100{rho}vector.
>
> I'm looking for other ways to accomplish the same thing in APL. Can
> you use an outer product or some other form of assignment?


Vn{<-}{iota}1E4
Vc{<-}1E4{rho}'abc'

Left argument of TIMER repeats test L times and divides total by L
100 TIMER'Vn{nul}.+20{rho}0' {@} for numeric Vn
0.00373
100 TIMER'{transpose}20 1E4{rho}Vc' {@} for character Vc
0.00045

for any V
10 TIMER'20/,[{iota}0]Vn'
0.0162
10 TIMER'20/,[{iota}0]Vc'
0.016
or
10 TIMER'{disclose}[1]20{rho}{enclose}Vn'
0.0182
10 TIMER'{disclose}[1]20{rho}{enclose}Vc'
0.0193

Ted
Reply With Quote
  #7  
Old 12-18-2007, 10:32 AM
Lance
Guest
 
Default Re: A vector to an array

On Dec 17, 11:22 am, aleph0 <apl68...@tiscali.co.uk> wrote:
> Try ...
>
> 20/[1],[.1]VEC
>
> This will replicate the first dimension 20 times to give you RHO = 20
> 100
>
> 20/,[1.1]VEC
>
> This will replicate the second dimension 20 times to give you RHO =
> 100 20
>
> On Dec 17, 5:53 pm, Lance <Lanc...@gmail.com> wrote:
>

Thanks. I've now learned about ravel with axis.

Lance
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 09:59 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.