Ask Your Question
0

Numpy array or list of random signs

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

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 +0100

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 +0100 )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 +0100

Seen: 1,915 times

Last updated: Aug 24 '13