Group Abstract Group Abstract

Message Boards Message Boards

0
|
92 Views
|
6 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to delete all instances of -1 from a table?

Posted 2 days ago

I have a table that outputs 1 of 2 values, 1 or -1 I'm trying to figure out how to delete all of the instances of -1 from the table but none of the delete options that I've tried work. My table is set up like this:

f = Table[e, {x, (n*3) + 1, (z*3) + (n/z), -2}];

e can only equal 1 or -1 so I thought the following line would work but it outputs nothing

g = DeleteElements[Table[{f}, {-1}], {x, (n*3) + 1, (z*3) + (n/z), -2}]

What am i missing?

POSTED BY: Chris Agee
6 Replies
Posted 1 day ago

Thanks for all of your suggestions I figured out what I was doing wrong, f is the quotient of two complex numbers I was only looking at the real portion and ignoring the unreal part, so in most cases I wasn't getting -1 or even +1.

POSTED BY: Chris Agee
Posted 1 day ago

nvm

POSTED BY: Eric Rimbey
DeleteCases[f, _?(Re[#] == -1 &)]

Another way:

DeleteCases[{1, 1, -1, 1, -1, -1, 1, -1}, -1]
POSTED BY: Gianluca Gorni

From your description, I assume your f table looks something like this:

{1, 1, -1, 1, -1, -1, 1, -1}

If I use DeleteElements[] on it as follows, I get the desired result:

DeleteElements[{1, 1, -1, 1, -1, -1, 1, -1}, {-1}]
(*  {1, 1, 1, 1} *)

It looks like your DeleteElements[] code does not end in {-1}]. Rather, you seem to have put the {-1}] in the middle of the Table[] code. This is probably the problem, unless there is a problem with f or e, which you did not show.

POSTED BY: Michael Rogers
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard