#!/bin/python
import numpy as np
layers_size = [5,40,40,3]
weights = []
length = len(layers_size)
#appreciate loop starting in 1 since you dont need
#weights #in the entry layer
#runs layers_size times - 1
for i in range(0, length):
weights.append([])
#Gives the amount of neurons for each layer
for j in range(0, layers_size[i]):
#Get the amount of neurons from the previous layer to
# the actual neuron so it saves layers_size[i] - 1
# numWeights for the actual neuron...
weights[i].append(np.random.randint(1, 101))
print(np.array(weights))
Выход:
[list([81, 53, 53, 55, 71])
list([34, 75, 12, 14, 9, 69, 56, 1, 98, 73, 14, 82, 60, 52, 13, 7, 14, 9, 5, 8, 24, 61, 75, 52, 82, 91, 67, 75, 22, 77, 84, 71, 83, 77, 56, 99, 94, 49, 100, 84])
list([45, 44, 71, 89, 16, 22, 41, 36, 42, 38, 53, 4, 25, 53, 16, 81, 47, 70, 9, 88, 81, 27, 66, 91, 97, 53, 41, 20, 20, 15, 77, 38, 60, 1, 30, 17, 55, 51, 33, 30])
list([43, 60, 17])]