10

Many/most questions are looking for how to do something, or how to do something faster. I have a question where I know how to do something, and am happy with the speed, but want a solution that is short while being easy to understand, especially for relative newcomers to Mathematica.

In[20]:= {bins, counts} = N[HistogramList[RandomVariate[NormalDistribution[5, 2], 100]]]

Out[20]= {{0., 2., 4., 6., 8., 10.}, {13., 19., 37., 28., 3.}}

In[21]:= Transpose[{Riffle[bins, bins], Flatten[{0, Riffle[counts, counts], 0}]}]

Out[21]= {{0., 0}, {0., 13.}, {2., 13.}, {2., 19.}, {4., 19.}, {4., 37.}, {6., 37.}, 
          {6., 28.}, {8., 28.}, {8., 3.}, {10., 3.}, {10., 0}}

Is this too subjective for the site?

  • 4
    "Is there a simpler and/or more intuitive way of achieving this behavior?" – Mike Bailey Jan 19 '12 at 5:50
  • I'd say yes, go for it. @MikeBantegui 's phrasing is ideal. – Verbeia Jan 19 '12 at 7:03
  • 1
    @Mike: Can you make an answer out of your comment? – Simon Jan 19 '12 at 7:52
  • related but not duplicate: my suggestion of a "elegant-code" tag – Verbeia Jan 29 '12 at 23:06
11

Personally, I strongly support questions like this. I think they are very important to allow them.

There is less code sharing among Mathematica users than among "regular" programmers (C, Java, etc.), so there are fewer opportunities to get feedback on code, or to even develop a style that could be generally accepted as idiomatic (because non communicating much means everyone would come up with their own style and habits).

If we have a place to talk about these things, we will all become better Mathematica programmers.

  • 1
    I second this. Asking if there is a simpler way to achieve something is definitely on topic. – rcollyer Jan 19 '12 at 17:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .