0

What do these two lines mean?

1. np.random.seed(1)
2. syn0 = 2*np.random.random((3,4))-1

I understand the first line is the starting point of the random generating numbers, what will make them generating the same sequence even though they have the same starting point?

The second line is the generation of the matrix 3x4 of the weights. Is the "1" related to the one in the seed? I don't actually understand why there are 2* and why they are random.random

I would expect the sum of the weights to be equal to 1 so that might in the purpose?

1 Answer 1

1

As np.random is a PRNG, it can be seeded and its seed to be set manually for reproducable results. Now it's being seeded with 1 and you'll always get the same results after resetting the seed to 1.

In [4]: np.random.seed?
Docstring:
seed(seed=None)

Seed the generator.

This method is called when `RandomState` is initialized. It can be
called again to re-seed the generator. For details, see `RandomState`.

Parameters
----------
seed : int or array_like, optional
    Seed for `RandomState`.
    Must be convertible to 32 bit unsigned integers.

Then the np.random.random() constructs you a matrix of random values:

In [5]: np.random.random?
Docstring:
random_sample(size=None)

Return random floats in the half-open interval [0.0, 1.0).

The rest is usual numpy arithmetic. A - 1 for a matrix A means that 1 is subtracted element-wise from A. And 2 * A is a normal scalar operation.

Sign up to request clarification or add additional context in comments.

Comments