让我说,你有一份名单,你只希望删除这些名单,其篇幅为零,例如:
a={{...},{...},{...},...}
DeleteCases[a, ?]
The What should the ?
?
让我说,你有一份名单,你只希望删除这些名单,其篇幅为零,例如:
a={{...},{...},{...},...}
DeleteCases[a, ?]
The What should the ?
?
可以:
a = {{1, 2, 3}, {4, 5}, {}, {5}}
b = DeleteCases[a, x_ /; Length[x] == 0]
{{1, 2, 3}, {4, 5}, {5}}
In[1]:= a={{1,2,3},{4,{5,5.5},{}},{},6,f,f[7],{8}}
Out[1]= {{1,2,3},{4,{5,5.5},{}},{},6,f,f[7],{8}}
纳赛尔提出的解决办法:
In[2]:= DeleteCases[a, x_/;Length[x]==0]
Out[2]= {{1,2,3},{4,{5,5.5},{}},f[7],{8}}
注 1. 如果你只想从第一级删除零(即{>>>>
)的长度清单,那么你可以使用。
In[3]:= DeleteCases[a, {}]
Out[3]= {{1,2,3},{4,{5,5.5},{}},6,f,f[7],{8}}
或如果您希望从所有各级删除,则使用<代码>ReplaceAll(/.
)。
In[4]:= a /. {} -> Sequence[]
Out[4]= {{1,2,3},{4,{5,5.5}},6,f,f[7],{8}}
I m trying to figure out how to use Mathematica to solve systems of equations where some of the variables and coefficients are vectors. A simple example would be something like where I know A, V, and ...
Is there any way to get at the actual messages generated during the evaluation of an expression in Mathematica? Say I m numerically solving an ODE and it blows up, like so In[1] := sol = NDSolve[{x [...
I know I can after the plot is done, to rotate it with my mouse to the desired angle. Now, I d like to know how to do the same through code.
Here is what I mean: alt text http://img63.imageshack.us/img63/7079/grwb3mmw2gq1bihvt1kb2dn.png Sometimes I don t know why, I get the names of functions blue. Is there any special reason?
I have a collection of points displayed in a graphic: alt text http://img69.imageshack.us/img69/874/plc1k1lrqynuyshgrdegvfy.jpg I d like to know if there is any command that will connect them ...
I need to plot a normal distribution and then shade some specific region of it. Right now I m doing this by creating a plot of the distribution and overlaying it with a RegionPlot. This is pretty ...
I generate very long and complex analytic expressions of the general form: (...something not so complex...)(...ditto...)(...ditto...)...lots... When I try to use Simplify, Mathematica grinds to a ...
Is it possible that when I Plot a function in Mathematica, it will automatically put near it it s equation(i.e. y = 2x) or even some other text? At first glance I don t find any option for it, but if ...