Ask Your Question
0

Numpy array or list of random signs

asked 2013-08-24 18:28:40 +0200

mresimulator gravatar image

Hi experts!

How can I obtain a numpy array or list of 'N'random signs? for example:

[1, -1, 1, 1 , -1, -1, 1 , 1, 1]

where N = 9.

Waiting for your answers.

Thanks a lot!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-08-24 20:36:24 +0200

Luca gravatar image

In pure python:

import random
[(-1)**random.randint(0,1) for i in range(9)]
edit flag offensive delete link more

Comments

Thanks Luca!!

mresimulator gravatar imagemresimulator ( 2013-08-24 21:32:48 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-08-24 18:28:40 +0200

Seen: 1,872 times

Last updated: Aug 24 '13