Message Boards Message Boards

1
|
6215 Views
|
3 Replies
|
7 Total Likes
View groups...
Share
Share this post:

Do operations on hierarchical Datasets?

Posted 7 years ago

I am having difficulties combining operations with Queries on hierarchical data sets.

Here is a contrived example hierarchical dataset:

dset = (Query[GroupBy["integer"]]@
    Dataset[AssociationThread[{"color", "integer", "vector1", 
          "vector2"} :> 
         #] & /@ 
      Table[{RandomColor[], Mod[i, 3], RandomReal[{-1, 1}], 
        RandomReal[{-1, 1}]}, {i, 12}]])[All, 
  All, {"color", "vector1", "vector2"}]

I'd like to compute the dot product of the vectors of length 4 in "vector1" and "vector2" column for each of the grouped rows.

I can do this easily by turning the dataset into a Normal expression, but I am trying to learn how to do it with Dataset and Query

POSTED BY: W. Craig Carter
3 Replies

Dear Zhu, Thank you for your excellent answer. I am sorry that the community site wasn't working very well for you.

POSTED BY: W. Craig Carter
Posted 7 years ago

Of course we can operate like this

dset[All, Transpose /* (#vector1.#vector2 &), {"vector1", "vector2"}]

Or

dset[All, Transpose /* Apply[Dot], {"vector1", "vector2"}]
POSTED BY: Yode Japhe
Posted 7 years ago
dset[All, Total, {"vector1", "vector2"} /* Apply[Times]]

enter image description here

Ps:I have to say this site is very unfriend to Chinese user.I cost almost one hour to access my account.I hope the Wolfram Research receive my complaint.

POSTED BY: Yode Japhe
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