English 中文(简体)
• 如何在数学表中删除Null符号?
原标题:How to remove the Null symbol in a Table in Mathematica?

我们需要在<条码>内使用<条码>If,例如<条码> 可使用[If[i<3, i],{i, 5}]。

但我希望结果为<代码>{1,2}。

这样做有什么办法?

EDIT:
What if we consider Table[If[i< 3, f[i]], {i, 5}] which gives {f[1], f[2], Null, Null, Null}

最佳回答

Concisely:

Table[If[i < 3, i, ## &[]], {i, 5}]

This works because the function ## & does not immediately evaluate.

## & is a "vanishing" function.

{1, 2, ## &[], 3, 4}
----> {1, 2, 3, 4}

See SlotSequence , for more information.

问题回答

作为一种替代办法,您可使用这一回答,该回答专门针对有条件的表层建设。 这里将如何研究:

In[12]:= tableGenAltMD[i,{i,5},#<3&]
Out[12]= {1,2}

最后一个论点是代表条件的职能。 事实上,如果一个人能够直接使用<条码>i<>->->(和/或其他代变量)的辛醇,那么这种合成物可能不会增加。

在以前的航道中,<代码># &[]可改为“内在编号Nothing

Table[If[i < 3, i, Nothing], {i, 5}]

专 员

{1, 2}

如果你使用“公平”而不是“纽埃”,那么你可以这样做。

Table[If[i < 3, i, Hold[Sequence[]]] // ReleaseHold, {i, 5}]

I wished for a long time that If would have Attribute SequenceHold. I think I once suggested this to WRI, but there are probably (good?) reasons for If to not hat this attribute. One can try, if one dares to change built-in Symbols (which one should probably not do):

Unprotect[If];
SetAttributes[If, SequenceHold];

之后,如果只是工作的话,就应当做到:

Table[If[i < 3, i, Sequence[]], {i, 5}]




相关问题
Instead of NULL, should I write `0x0` or `0`?

I know that you are supposed to use 0 instead of NULL in c++ (even though NULL is defined as 0 in C++ most of the time). Recently I came across some code where 0x0 was used instead, though. What is ...

SELECT the newest record with a non null value in one column

I have table data which looks like this id | keyword | count | date 1 | ipod | 200 | 2009-08-02 2 | ipod | 250 | 2009-09-01 3 | ipod | 150 | 2009-09-04 4 | ipod | NULL | 2009-09-07 Now what I am ...

C#: Range intersection when endpoints are null (infinity)

Ok, I have these intersection methods to work with ranges, and they work well as long as the range endpoints are not null: public static bool Intersects<T>(this Range<T> first, Range<T&...

How can I store NULLs in NOT NULL field?

I just came across NULL values in NOT-NULL fields in our test database. How could they get there? I know that NOT-NULL constraints can be altered with NOVALIDATE clause, but that would change table s ...

热门标签