Message Boards Message Boards

0
|
5194 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Create 3D array from a 2D matrix?

Posted 6 years ago

I have a matrix ,e.g., d2={{3,2},{4,1},{5,6}}, and I want to create a 3D array, e.g., d3={{3,18,2},{4,32,1},{5,50,6}} from the 2D matrix, note that the inserted middle element is 2 times the square of the first element . I can not figure out how to do this in mathematica

POSTED BY: mohamed alzenad
2 Replies

d2 = {{3, 2}, {4, 1}, {5, 6}}

a = {18, 32, 50}

d3 = Table[{d2[[n, 1]], a[[n]], d2[[n, 2]]}, {n, 1, 3}]

This will yield

3 18 2

4 32 1

5 50 6

POSTED BY: Gustavo Gordillo
In[1]:= d = {{3, 2}, {4, 1}, {5, 6}};

In[2]:= d /. {a_, b_} -> {a, 2*a^2, b}

Out[2]= {{3, 18, 2}, {4, 32, 1}, {5, 50, 6}}
POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract