Converting from “matrix” data into “coordinate” dataListVectorPlot3DOrganise data in tableHow to...

How can a demon take control of a human body during REM sleep?

Yet another question on sums of the reciprocals of the primes

Sampling from Gaussian mixture models, when are the sampled data independent?

Giving a career talk in my old university, how prominently should I tell students my salary?

What is the purpose of a disclaimer like "this is not legal advice"?

What can I do if someone tampers with my SSH public key?

Can the Witch Sight warlock invocation see through the Mirror Image spell?

If nine coins are tossed, what is the probability that the number of heads is even?

Can one live in the U.S. and not use a credit card?

What is Tony Stark injecting into himself in Iron Man 3?

Cycles on the torus

Do black holes violate the conservation of mass?

Why do we say 'Pairwise Disjoint', rather than 'Disjoint'?

I am the person who abides by rules, but breaks the rules. Who am I?

Are small insurances worth it?

Difference between `nmap local-IP-address` and `nmap localhost`

Why aren't there more Gauls like Obelix?

Was it really inappropriate to write a pull request for the company I interviewed with?

Optimal Proportions for Flying Humans

Logistic regression BIC: what's the right N?

What was so special about The Piano that Ada was willing to do anything to have it?

Idiom for feeling after taking risk and someone else being rewarded

Help! My Character is too much for her story!

What is this tube in a jet engine's air intake?



Converting from “matrix” data into “coordinate” data


ListVectorPlot3DOrganise data in tableHow to multiply specific columns in a matrix of data?How do I partition a matrix?Reshaping list of 2D points by first coordinateBin a large matrixTurning table into association for Classifysubtraction of Y valuesInserting columns into a large table of data and converting it into a {x,y,z} listConvert Negative Integers into Signed Binary?













2












$begingroup$


Say I have data which looks like data1 - this is "matrix" like data (is there a better descriptor?). The data looks like a matrix, and at each point in the matrix, it has a value. I can plot these in ListContourPlot and the like. e.g.



datafunction = MultinormalDistribution[{0, 0}, {{2, 1/2}, {1/2, 1}}];

(* matrix like data *)

data1 = N[ Table[PDF[datafunction, {x, y}] /. {x -> xinsert, y -> yinsert}, {xinsert, -4, 4, 1}, {yinsert, -2, 2, 1}]];
ListContourPlot[data1]


enter image description here
However, I can also create the same effect by making "coordinate" like data, where the data is a list of coordinates.



(* coordinate like data *) 

data2 = RandomVariate[MultinormalDistribution[{0, 0}, {{2, 1/2}, {1/2, 1}}], 1000];
ListPlot[data2]


enter image description here
How would I convert data1 into data2? How do I convert matrix-like into coordinate-like?



I need to do some PCA analysis, I require the data to be in the form of individual points.










share|improve this question











$endgroup$








  • 1




    $begingroup$
    How do you think one could infer the individual counts from a total count? Once we have totaled data and thrown away the parts there is no way to reconstruct them. The mapping between sums and their constituents is not bijective.
    $endgroup$
    – Sjoerd C. de Vries
    8 hours ago
















2












$begingroup$


Say I have data which looks like data1 - this is "matrix" like data (is there a better descriptor?). The data looks like a matrix, and at each point in the matrix, it has a value. I can plot these in ListContourPlot and the like. e.g.



datafunction = MultinormalDistribution[{0, 0}, {{2, 1/2}, {1/2, 1}}];

(* matrix like data *)

data1 = N[ Table[PDF[datafunction, {x, y}] /. {x -> xinsert, y -> yinsert}, {xinsert, -4, 4, 1}, {yinsert, -2, 2, 1}]];
ListContourPlot[data1]


enter image description here
However, I can also create the same effect by making "coordinate" like data, where the data is a list of coordinates.



(* coordinate like data *) 

data2 = RandomVariate[MultinormalDistribution[{0, 0}, {{2, 1/2}, {1/2, 1}}], 1000];
ListPlot[data2]


enter image description here
How would I convert data1 into data2? How do I convert matrix-like into coordinate-like?



I need to do some PCA analysis, I require the data to be in the form of individual points.










share|improve this question











$endgroup$








  • 1




    $begingroup$
    How do you think one could infer the individual counts from a total count? Once we have totaled data and thrown away the parts there is no way to reconstruct them. The mapping between sums and their constituents is not bijective.
    $endgroup$
    – Sjoerd C. de Vries
    8 hours ago














2












2








2





$begingroup$


Say I have data which looks like data1 - this is "matrix" like data (is there a better descriptor?). The data looks like a matrix, and at each point in the matrix, it has a value. I can plot these in ListContourPlot and the like. e.g.



datafunction = MultinormalDistribution[{0, 0}, {{2, 1/2}, {1/2, 1}}];

(* matrix like data *)

data1 = N[ Table[PDF[datafunction, {x, y}] /. {x -> xinsert, y -> yinsert}, {xinsert, -4, 4, 1}, {yinsert, -2, 2, 1}]];
ListContourPlot[data1]


enter image description here
However, I can also create the same effect by making "coordinate" like data, where the data is a list of coordinates.



(* coordinate like data *) 

data2 = RandomVariate[MultinormalDistribution[{0, 0}, {{2, 1/2}, {1/2, 1}}], 1000];
ListPlot[data2]


enter image description here
How would I convert data1 into data2? How do I convert matrix-like into coordinate-like?



I need to do some PCA analysis, I require the data to be in the form of individual points.










share|improve this question











$endgroup$




Say I have data which looks like data1 - this is "matrix" like data (is there a better descriptor?). The data looks like a matrix, and at each point in the matrix, it has a value. I can plot these in ListContourPlot and the like. e.g.



datafunction = MultinormalDistribution[{0, 0}, {{2, 1/2}, {1/2, 1}}];

(* matrix like data *)

data1 = N[ Table[PDF[datafunction, {x, y}] /. {x -> xinsert, y -> yinsert}, {xinsert, -4, 4, 1}, {yinsert, -2, 2, 1}]];
ListContourPlot[data1]


enter image description here
However, I can also create the same effect by making "coordinate" like data, where the data is a list of coordinates.



(* coordinate like data *) 

data2 = RandomVariate[MultinormalDistribution[{0, 0}, {{2, 1/2}, {1/2, 1}}], 1000];
ListPlot[data2]


enter image description here
How would I convert data1 into data2? How do I convert matrix-like into coordinate-like?



I need to do some PCA analysis, I require the data to be in the form of individual points.







list-manipulation data-structures






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 7 hours ago







Tomi

















asked 9 hours ago









TomiTomi

974514




974514








  • 1




    $begingroup$
    How do you think one could infer the individual counts from a total count? Once we have totaled data and thrown away the parts there is no way to reconstruct them. The mapping between sums and their constituents is not bijective.
    $endgroup$
    – Sjoerd C. de Vries
    8 hours ago














  • 1




    $begingroup$
    How do you think one could infer the individual counts from a total count? Once we have totaled data and thrown away the parts there is no way to reconstruct them. The mapping between sums and their constituents is not bijective.
    $endgroup$
    – Sjoerd C. de Vries
    8 hours ago








1




1




$begingroup$
How do you think one could infer the individual counts from a total count? Once we have totaled data and thrown away the parts there is no way to reconstruct them. The mapping between sums and their constituents is not bijective.
$endgroup$
– Sjoerd C. de Vries
8 hours ago




$begingroup$
How do you think one could infer the individual counts from a total count? Once we have totaled data and thrown away the parts there is no way to reconstruct them. The mapping between sums and their constituents is not bijective.
$endgroup$
– Sjoerd C. de Vries
8 hours ago










2 Answers
2






active

oldest

votes


















4












$begingroup$

The reshaping can be done in several ways. Below is given one using SparseArray.



First generating the data (simpler than in the question):



datafunction = MultinormalDistribution[{0, 0}, {{2, 1/2}, {1/2, 1}}];

data1 = N[Table[PDF[datafunction][{x, y}], {x, -4, 4, 1}, {y, -2, 2, 1}]];

MatrixForm[data1]


Make index-to-value associations corresponding to the ranges used to make data1:



aX = AssociationThread[Range[Length[#]], #] &@Range[-4, 4, 1];
aY = AssociationThread[Range[Length[#]], #] &@Range[-2, 2, 1];


Convert to a sparse array, take the corresponding rules, and map the {x,y} indexes to the actual x's and y's.



arules = Most[ArrayRules[SparseArray[data1]]];
data2 = Map[{aX[#[[1, 1]]], aY[#[[1, 2]]], #[[2]]} &, arules]


Plot (note the axes ticks):



ListContourPlot[data2]


enter image description here






share|improve this answer









$endgroup$





















    1












    $begingroup$

    An alternative approach based on Rescaleing the "NonzeroPositions" of SparseArray[data1]:



    xrange = {-4, 4};
    yrange = {-2, 2};
    sa = SparseArray[data1];
    nzp = sa["NonzeroPositions"];
    nzv = sa["NonzeroValues"];
    data2b = Join[Transpose[Rescale[#, MinMax@#, #2] & @@@
    Thread[ {Transpose@nzp, {xrange, yrange}}]], List /@ nzv, 2];

    data2b == data2 (* from Anton's answer *)



    True







    share|improve this answer









    $endgroup$













      Your Answer





      StackExchange.ifUsing("editor", function () {
      return StackExchange.using("mathjaxEditing", function () {
      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
      });
      });
      }, "mathjax-editing");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "387"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192942%2fconverting-from-matrix-data-into-coordinate-data%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      4












      $begingroup$

      The reshaping can be done in several ways. Below is given one using SparseArray.



      First generating the data (simpler than in the question):



      datafunction = MultinormalDistribution[{0, 0}, {{2, 1/2}, {1/2, 1}}];

      data1 = N[Table[PDF[datafunction][{x, y}], {x, -4, 4, 1}, {y, -2, 2, 1}]];

      MatrixForm[data1]


      Make index-to-value associations corresponding to the ranges used to make data1:



      aX = AssociationThread[Range[Length[#]], #] &@Range[-4, 4, 1];
      aY = AssociationThread[Range[Length[#]], #] &@Range[-2, 2, 1];


      Convert to a sparse array, take the corresponding rules, and map the {x,y} indexes to the actual x's and y's.



      arules = Most[ArrayRules[SparseArray[data1]]];
      data2 = Map[{aX[#[[1, 1]]], aY[#[[1, 2]]], #[[2]]} &, arules]


      Plot (note the axes ticks):



      ListContourPlot[data2]


      enter image description here






      share|improve this answer









      $endgroup$


















        4












        $begingroup$

        The reshaping can be done in several ways. Below is given one using SparseArray.



        First generating the data (simpler than in the question):



        datafunction = MultinormalDistribution[{0, 0}, {{2, 1/2}, {1/2, 1}}];

        data1 = N[Table[PDF[datafunction][{x, y}], {x, -4, 4, 1}, {y, -2, 2, 1}]];

        MatrixForm[data1]


        Make index-to-value associations corresponding to the ranges used to make data1:



        aX = AssociationThread[Range[Length[#]], #] &@Range[-4, 4, 1];
        aY = AssociationThread[Range[Length[#]], #] &@Range[-2, 2, 1];


        Convert to a sparse array, take the corresponding rules, and map the {x,y} indexes to the actual x's and y's.



        arules = Most[ArrayRules[SparseArray[data1]]];
        data2 = Map[{aX[#[[1, 1]]], aY[#[[1, 2]]], #[[2]]} &, arules]


        Plot (note the axes ticks):



        ListContourPlot[data2]


        enter image description here






        share|improve this answer









        $endgroup$
















          4












          4








          4





          $begingroup$

          The reshaping can be done in several ways. Below is given one using SparseArray.



          First generating the data (simpler than in the question):



          datafunction = MultinormalDistribution[{0, 0}, {{2, 1/2}, {1/2, 1}}];

          data1 = N[Table[PDF[datafunction][{x, y}], {x, -4, 4, 1}, {y, -2, 2, 1}]];

          MatrixForm[data1]


          Make index-to-value associations corresponding to the ranges used to make data1:



          aX = AssociationThread[Range[Length[#]], #] &@Range[-4, 4, 1];
          aY = AssociationThread[Range[Length[#]], #] &@Range[-2, 2, 1];


          Convert to a sparse array, take the corresponding rules, and map the {x,y} indexes to the actual x's and y's.



          arules = Most[ArrayRules[SparseArray[data1]]];
          data2 = Map[{aX[#[[1, 1]]], aY[#[[1, 2]]], #[[2]]} &, arules]


          Plot (note the axes ticks):



          ListContourPlot[data2]


          enter image description here






          share|improve this answer









          $endgroup$



          The reshaping can be done in several ways. Below is given one using SparseArray.



          First generating the data (simpler than in the question):



          datafunction = MultinormalDistribution[{0, 0}, {{2, 1/2}, {1/2, 1}}];

          data1 = N[Table[PDF[datafunction][{x, y}], {x, -4, 4, 1}, {y, -2, 2, 1}]];

          MatrixForm[data1]


          Make index-to-value associations corresponding to the ranges used to make data1:



          aX = AssociationThread[Range[Length[#]], #] &@Range[-4, 4, 1];
          aY = AssociationThread[Range[Length[#]], #] &@Range[-2, 2, 1];


          Convert to a sparse array, take the corresponding rules, and map the {x,y} indexes to the actual x's and y's.



          arules = Most[ArrayRules[SparseArray[data1]]];
          data2 = Map[{aX[#[[1, 1]]], aY[#[[1, 2]]], #[[2]]} &, arules]


          Plot (note the axes ticks):



          ListContourPlot[data2]


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 7 hours ago









          Anton AntonovAnton Antonov

          24k167114




          24k167114























              1












              $begingroup$

              An alternative approach based on Rescaleing the "NonzeroPositions" of SparseArray[data1]:



              xrange = {-4, 4};
              yrange = {-2, 2};
              sa = SparseArray[data1];
              nzp = sa["NonzeroPositions"];
              nzv = sa["NonzeroValues"];
              data2b = Join[Transpose[Rescale[#, MinMax@#, #2] & @@@
              Thread[ {Transpose@nzp, {xrange, yrange}}]], List /@ nzv, 2];

              data2b == data2 (* from Anton's answer *)



              True







              share|improve this answer









              $endgroup$


















                1












                $begingroup$

                An alternative approach based on Rescaleing the "NonzeroPositions" of SparseArray[data1]:



                xrange = {-4, 4};
                yrange = {-2, 2};
                sa = SparseArray[data1];
                nzp = sa["NonzeroPositions"];
                nzv = sa["NonzeroValues"];
                data2b = Join[Transpose[Rescale[#, MinMax@#, #2] & @@@
                Thread[ {Transpose@nzp, {xrange, yrange}}]], List /@ nzv, 2];

                data2b == data2 (* from Anton's answer *)



                True







                share|improve this answer









                $endgroup$
















                  1












                  1








                  1





                  $begingroup$

                  An alternative approach based on Rescaleing the "NonzeroPositions" of SparseArray[data1]:



                  xrange = {-4, 4};
                  yrange = {-2, 2};
                  sa = SparseArray[data1];
                  nzp = sa["NonzeroPositions"];
                  nzv = sa["NonzeroValues"];
                  data2b = Join[Transpose[Rescale[#, MinMax@#, #2] & @@@
                  Thread[ {Transpose@nzp, {xrange, yrange}}]], List /@ nzv, 2];

                  data2b == data2 (* from Anton's answer *)



                  True







                  share|improve this answer









                  $endgroup$



                  An alternative approach based on Rescaleing the "NonzeroPositions" of SparseArray[data1]:



                  xrange = {-4, 4};
                  yrange = {-2, 2};
                  sa = SparseArray[data1];
                  nzp = sa["NonzeroPositions"];
                  nzv = sa["NonzeroValues"];
                  data2b = Join[Transpose[Rescale[#, MinMax@#, #2] & @@@
                  Thread[ {Transpose@nzp, {xrange, yrange}}]], List /@ nzv, 2];

                  data2b == data2 (* from Anton's answer *)



                  True








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 12 mins ago









                  kglrkglr

                  188k10203421




                  188k10203421






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Mathematica Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      Use MathJax to format equations. MathJax reference.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192942%2fconverting-from-matrix-data-into-coordinate-data%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

                      How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

                      變成蝙蝠會怎樣? 參考資料 外部連結 导航菜单Thomas Nagel, "What is it like to be a...