Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.8K Views
|
11 Replies
|
4 Total Likes
View groups...
Share
Share this post:

How to use 1D SparseArray instead of Table?

Posted 10 years ago

Hello, everyone.

I want to ask you very very simple thing, but it looks strange to me at least. I have to use 1 dim SparseArray function instead of Table. But I don't know why the following example is not possible.

\[Chi]square = SparseArray[1 -> 3, 4]
Position[\[Chi]square, 3]

When Table is used, then it works fine (even the depth of array and table are same). Can you tell me what is reason for this ? Thank you in advance.

POSTED BY: hwoarang Polar
11 Replies

Examples of atomic objects include SparseArray, Graph, (Boundary)MeshRegion, Association, Dispatch and a few more obscure/undocumented raw types. An exhaustive list is unlikely to be very useful.

POSTED BY: Ilian Gachevski

Maybe not useful, but still interesting.

POSTED BY: Frank Kampas
POSTED BY: Frank Kampas
Posted 10 years ago

And could splitting SparseArrays be a new source of clean energy?

POSTED BY: David Keith
POSTED BY: Ilian Gachevski
POSTED BY: Frank Kampas
POSTED BY: Frank Kampas
Posted 10 years ago

Thank you,Frank for the reply.

But the strange thing is that when I use SparseArray, Position command cannot find the position of the element that I specified like below. Did I misunderstand something ?

In[125]:= \[Chi]square = SparseArray[1 -> 3, 4];
Position[\[Chi]square, 3]

Out[126]= {}
POSTED BY: hwoarang Polar
Posted 10 years ago

Ah, sorry. I found it.

When I use 'Normal' command, Position can read it.

In[146]:= \[Chi]square = Normal[SparseArray[1 -> 3, 4]]
Position[\[Chi]square, 3]

Out[146]= {3, 0, 0, 0}

Out[147]= {{1}}

Thank you and have a good day!

POSTED BY: hwoarang Polar
Posted 10 years ago

Thank you very much for the reply, Frank.

But I mean that why Position command is not working with SparseArray. This gives me blank. When I use data with parenthesis as follows, it gives me the position of the element. Can you give me a hint ?

In[98]:= \[Chi]square = {3, 1, 5, 4}

Out[98]= {3, 1, 5, 4}

In[99]:= Position[\[Chi]square, 1]

Out[99]= {{2}}
POSTED BY: hwoarang Polar
In[1]:= \[Chi]square = SparseArray[1 -> 3, 4]

Out[1]= SparseArray[< 1 >, {4}]

In[2]:= Normal @ \[Chi]square

Out[2]= {3, 0, 0, 0}
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