wolfram-mathematica

Reading UTF-8 text files with ReadList

℡╲_俬逩灬. 提交于 2019-12-01 05:29:40
Is it possible to use ReadList to read UTF-8 (or any other) encoded text files using ReadList[..., Word] , or is it ASCII-only? If it's ASCII-only, is it possible to "fix" the encoding of the already read data with good performance (i.e. preserving the performance advantages of ReadList over Import )? Import[..., CharacterEncoding -> "UTF8"] works but it's quite a bit slower than ReadList . $CharacterEncoding has no effect on ReadList Download a sample UTF-8 encoded file here. For testing performance on a large input, see the test file in this question . Here are the timings of the answers on

picking specific symbol definitions in mathematica (not transformation rules)

北城余情 提交于 2019-12-01 04:58:11
I have a following problem. f[1]=1; f[2]=2; f[_]:=0; dvs = DownValues[f]; this gives dvs = { HoldPattern[f[1]] :> 1, HoldPattern[f[2]] :> 2, HoldPattern[f[_]] :> 0 } My problem is that I would like to extract only definitions for f[1] and f[2] etc but not the general definition f[_], and I do not know how to do this. I tried, Cases[dvs, HoldPattern[ f[_Integer] :> _ ]] (*) but it gives me nothing, i.e. the empty list. Interestingly, changing HoldPattern into temporary^footnote dvs1 = {temporary[1] :> 1, temporary[2] :> 2, temporary[_] :> 0} and issuing Cases[dvs1, HoldPattern[temporary[

Font sizes print smaller than indicated

谁说胖子不能爱 提交于 2019-12-01 04:48:05
I am wondering why a 12 point Arial font, displayed on-screen in Mathematica, delivers output to my printer that is measureably smaller than 12 points when compared to output from other programs? I realize there has been some discussion of this behavior over in the Mathgroup moderated email list through the years, but I just haven't heard/read any really satisfying answers to this. Now that I am using Mathematica 8.0.1 (Windows 7 64 bit) the behavior seems even worse. I have set the option inspector to use 16 point Arial, which is printing more like 10 point Arial. Has anyone else noticed this

Controlling the Rasterize[] width for notebook-related expressions

a 夏天 提交于 2019-12-01 04:20:09
问题 Update Mr Wizard's answer gives pixel-perfect results, but it is Windows-only and destroys the clipboard contents. My answer should work on any platform, but it's less precise: e.g. it omits In/Out labels. It does allow setting the rasterization width though. This problem came up when I was trying to make a preview window for an image uploader (see the end of that answer). I would like to create a palette button that will upload the current notebook selection as an image. Before uploading, I

Why is a big loop within a small loop faster than a small loop within a big one?

北战南征 提交于 2019-12-01 04:16:27
问题 This is my Perl code $big=10_000_000; #A:big loop outside my $begin_time = time; foreach my $i (1..$big) { foreach my $p (1..10){ } } my $end_time = time; my $t1=$end_time-$begin_time; #B:small loop outside my $begin_time = time; foreach my $i (1..10){ foreach my $p (1..$big){ } } my $end_time = time; my $t2=$end_time-$begin_time; #output print $t1; print "\n"; print $t2; t1=8 seconds t2=3 seconds And the mathematica code: Timing[Do[2, {i, 1, 10}, {j, 2*1, 10^7}]] output:{14.328, Null} Timing

ConvexHull in Graphics - Mathematica

£可爱£侵袭症+ 提交于 2019-12-01 03:55:29
问题 Trying to plot a ConvexHull Using PlanarGraphPlot from the ComputationalGeometry package, it does not work when used in graphics. Any Idea on how to plot the ConvexHull using Graphics ? 回答1: Needs["ComputationalGeometry`"] pts = RandomReal[{0, 10}, {60, 2}]; Graphics[ { Point@pts, FaceForm[], EdgeForm[Red], Polygon@pts[[ConvexHull[pts]]] } ] or cpts = pts[[ConvexHull[pts]]]; AppendTo[cpts, cpts[[1]]]; Graphics[ { Point@pts, Red, Line@cpts } ] 回答2: Not sure exactly what is wanted. Maybe the

Simple way to delete a matrix column in Mathematica

﹥>﹥吖頭↗ 提交于 2019-12-01 03:50:07
I am trying to delete both a matrix in mathematica. An inelegant way of doing it is as I do below, i.e specifying it in a new matrix as S = Table[ Ss[[If[i < t, i, i + 1]]][[If[j < t, j, j + 1]]], {i, q}, {j, q}]; where the goal is to eliminate row and column t. Indeed delete a line is easy Delete[Ss,t]. For the column column I suppose I could do Transpose[Delete[Transpose[Ss,t]]] My primary concern is to do it in a way that executes the fastest way possible. More generally, is there a Mathematica operator that makes it as easy to slice and dice matrix columns as it is to do for rows without

Reading UTF-8 text files with ReadList

我的未来我决定 提交于 2019-12-01 03:19:08
问题 Is it possible to use ReadList to read UTF-8 (or any other) encoded text files using ReadList[..., Word] , or is it ASCII-only? If it's ASCII-only, is it possible to "fix" the encoding of the already read data with good performance (i.e. preserving the performance advantages of ReadList over Import )? Import[..., CharacterEncoding -> "UTF8"] works but it's quite a bit slower than ReadList . $CharacterEncoding has no effect on ReadList Download a sample UTF-8 encoded file here. For testing

Font sizes print smaller than indicated

人盡茶涼 提交于 2019-12-01 01:59:12
问题 I am wondering why a 12 point Arial font, displayed on-screen in Mathematica, delivers output to my printer that is measureably smaller than 12 points when compared to output from other programs? I realize there has been some discussion of this behavior over in the Mathgroup moderated email list through the years, but I just haven't heard/read any really satisfying answers to this. Now that I am using Mathematica 8.0.1 (Windows 7 64 bit) the behavior seems even worse. I have set the option

Define Custom Notation in Mathematica

早过忘川 提交于 2019-12-01 00:23:35
I often need to extract to restrict value lists to sublists, ie if vals gives values of vars={x1,x2,x3,x4} , and I need values of svars={x2,x4} I do restrict[list,vars,svars] where restrict[vars_, svars_, vals_] := Extract[vals, Flatten[Position[vars, #] & /@ svars, 1]] I'd like to improve code readability, perhaps by defining following custom notation for restrict[vars,svars,vals] (source: yaroslavvb.com ) My questions are What is a good way to implement this? Is this a good idea altogether? Good notations can be very useful - but I'm not sure that this particular one is needed... That said,