Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

MatrixTemplate (Generalization)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28425] MatrixTemplate (Generalization)
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Wed, 18 Apr 2001 03:23:28 -0400 (EDT)
  • References: <9bgf1v$ddq@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

This extends the idea to tensors of arbitrary rank

TensorTemplate[x_, dims_]:=
  Fold[PadRight[{},#2,{#1}]&, x, Reverse[dims]]

TensorTemplate[0,{3,4,5}]

        {{{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}},
         {{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}},
         {{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}}
        }

Dimensions[%]

        {3,4,5}

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Allan Hayes" <hay at haystack.demon.co.uk> wrote in message
news:9bgf1v$ddq at smc.vnet.net...
>
> Clear["`*"]
>
> CreateMatrix[x_, m_, n_] := PadRight[{}, m, {PadRight[{}, {n}, {x}]}]
>
> Check
>
> CreateMatrix[0,3,5]
>
>         {{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}}
>
>
> --
> Allan
> ---------------------
> Allan Hayes
> Mathematica Training and Consulting
> Leicester UK
> www.haystack.demon.co.uk
> hay at haystack.demon.co.uk
> Voice: +44 (0)116 271 4198
> Fax: +44 (0)870 164 0565
>
>
>
>




  • Prev by Date: Re: Can Mathematica be used as expert system (rule-based computations like CLIPS?)
  • Next by Date: Re: conditionals during nonlinear regression
  • Previous by thread: Re: Summation Formulae Table
  • Next by thread: Bug in Integrate?