Ask Your Question
0

Numpy array or list of random signs

asked 2013-08-24 11:28:40 -0500

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 13:36:24 -0500

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 14:32:48 -0500 )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 11:28:40 -0500

Seen: 580 times

Last updated: Aug 24 '13