Message Boards Message Boards

0
|
6568 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Can I use Range for this lists

Posted 10 years ago

{1, -2, 3, -4, 5, -6, 7, -8, 9, -10}

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

POSTED BY: Camilo Pacheco
2 Replies

Another try

In[47]:= o = 0; Range[10] /. x_Integer :> (-1)^Mod[o++, 2] x
Out[47]= {1, -2, 3, -4, 5, -6, 7, -8, 9, -10}

In[46]:= o = 0; ConstantArray[1, 7] /. x_Integer :> (-1)^Mod[o++, 2] x
Out[46]= {1, -1, 1, -1, 1, -1, 1}
POSTED BY: Udo Krause

Try:

-(-1)^Range[10]Range[10]
-(-1)^Range[10]
POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract