turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Is there an alternative to Shape function

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Aug 17, 2017 11:41 AM
(1156 views)

All,

I would like to know if there is a good alternative to the "Shape" function (even UDF's - user defined functions are welcome) .

```
// Generate Random Data
TestData = Random Shuffle(Random Index(10^4,10^3));
// Reshape the data using Shape function
TestData1 = Shape(TestData,10,N Rows(TestData)/10);
// Visualize data as data table
dt = As Table(TestData);
dt1 = As Table(TestData1);
```

Visualize original raw random data - dt1

Result of Shape function

What I am hoping to achieve is convert the long format in dt1 or screenshot1 into wide format i.e.

Take "n" elements of Column1 and form a new column .

This is acheived using reshape function in most environments like Matlab and R . Wondering if there is a better way to do this with "Shape" or an alternative function .

Best

Uday

Best

Uday

Uday

Solved! Go to Solution.

2 ACCEPTED SOLUTIONS

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Aug 17, 2017 11:56 AM
(2259 views)

Solution

You may get what you need from the pull down menus by using

Tables==>Split

or

Tables==>Transpose

Jim

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Aug 17, 2017 12:57 PM
(2236 views)

Solution

It isn't wrong to mix matrix and data table operations but it isn't necessary, either. Matrices offer many advantages over data tables in a case like this, though. These simple examples illustrate how you might form matrices with random elements of any shape:

```
Names Default to Here( 1 );
n = 10; // rows
m = 10; // columns
// generate matrix in steps
x = J( n*m, 1, Random Integer( 1, 6 ) ); // column vector of six-sided die rolls
x = Shape( x, n, m ); // form into columns row-wise
y = Transpose( x ); // other way
Show( x, y ); // see what you got
// generate a pattern matrix in a single step
i = 1;
x = J( n, m, i++ ); // row-wise
y = Transpose( x ); // other way
Show( x, y ); // see what you got
// generate a n by m matrix of random elements in a single step
x = J( n, m, Random Integer( 1, 6 ) ); // row-wise
y = Transpose( x ); // other way
Show( x, y ); // see what you got
```

Learn it once, use it forever!

6 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Aug 17, 2017 11:56 AM
(2260 views)

You may get what you need from the pull down menus by using

Tables==>Split

or

Tables==>Transpose

Jim

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Aug 17, 2017 12:10 PM
(1145 views)

In addition to Jim's answer, your script is really close. I would not expect JMP to work exactly the same as MATLAB or R, but it can accomplish the same results. The **Shape()** function in JMP works row-wise instead of column-wise as you expected. Simply apply the **Transpose()** function to the result returned by the Shape() function:

```
// Reshape the data using Shape function
TestData1 = Transpose( Shape(TestData,10,N Rows(TestData)/10) );
```

Learn it once, use it forever!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Aug 17, 2017 12:35 PM
(1133 views)

@markbailey :

I have already tried that - however , the result looks like below - where I would have expected just 10 rows per column based on the function call .

@txnelson

Can you provide an example of how to exactly call "Split" function to accomplish this as well .

Best

Uday

Uday

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Aug 17, 2017 12:57 PM
(2237 views)

It isn't wrong to mix matrix and data table operations but it isn't necessary, either. Matrices offer many advantages over data tables in a case like this, though. These simple examples illustrate how you might form matrices with random elements of any shape:

```
Names Default to Here( 1 );
n = 10; // rows
m = 10; // columns
// generate matrix in steps
x = J( n*m, 1, Random Integer( 1, 6 ) ); // column vector of six-sided die rolls
x = Shape( x, n, m ); // form into columns row-wise
y = Transpose( x ); // other way
Show( x, y ); // see what you got
// generate a pattern matrix in a single step
i = 1;
x = J( n, m, i++ ); // row-wise
y = Transpose( x ); // other way
Show( x, y ); // see what you got
// generate a n by m matrix of random elements in a single step
x = J( n, m, Random Integer( 1, 6 ) ); // row-wise
y = Transpose( x ); // other way
Show( x, y ); // see what you got
```

Learn it once, use it forever!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Aug 17, 2017 1:10 PM
(1124 views)

When you become used to vectorized operations, you will think about the shape the whole way through, forwards and backwards. Applying only the **Transpose()** function won't give you what you want, of course. You have to change the **Shape()** function call in concert. In particular, you have to swap the number of rows and columns when you shape the original vector in anticipation of the transposition. Like this:

```
// Generate Random Data
TestData = Random Index( 10^4, 10^3 );
// Reshape the data using Shape function
TestData1 = Transpose( Shape( TestData, N Rows(TestData)/10, 10 ) );
// Visualize data as data table
dt = As Table( TestData );
dt1 = As Table( TestData1 );
```

Learn it once, use it forever!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Aug 17, 2017 1:24 PM
(1113 views)

Run the

File==>Split

it will produce a new data table. Go to the "Table Panel" at the upper left side of the new table. There you will find an entry named "Source". Right click on it and select "Edit". It will show you the code it used to create the new data table.

Jim