Problem with saving weights

84 views
Skip to first unread message

David Braune

unread,
Apr 22, 2021, 5:21:50 PM4/22/21
to Machine Learning for Physicists
Hi

I tried to save some random generated weights, cause the generated images look so pretty. I used savetxt, but I always get an error (Too many indecies for array) when using the reconstructed arrays even though they are identical to the original ones.
You can find the notebook here:

Thanks for reading!

Mehdi Aslani

unread,
Apr 23, 2021, 4:14:08 PM4/23/21
to Machine Learning for Physicists
Hi David
What are 'Weights2' and 'Biases2'?
Screen Shot 1400-02-04 at 00.43.21.png

David Braune

unread,
Apr 23, 2021, 5:06:03 PM4/23/21
to Machine Learning for Physicists
Hi Mehdi!

This name was only temporarely used to compare the arrays reconstructed from the txt to the original ones to check wether they are identical. You need to rename one of those yourself.

Mehdi Aslani

unread,
Apr 23, 2021, 6:26:04 PM4/23/21
to Machine Learning for Physicists
OK, then the question is:
why are you giving 'y_out' two indeces(y_out[:,0]) while it's a 1D array?!
Screen Shot 1400-02-04 at 02.46.18.png

David Braune

unread,
Apr 23, 2021, 7:19:03 PM4/23/21
to Machine Learning for Physicists
Well that's strange! Cause it works when you use the weights and biases directly. Of course it works; it's been written by Prof Marquardt. I'll check that out tomorrow.

Fatimah Ahmadi

unread,
Apr 24, 2021, 1:35:50 AM4/24/21
to Machine Learning for Physicists
The root of the problem is the following, there is a difference between the array of shape (n, ) and (n, 1) in  NumPy. So you need to reshape WeightsFinal when reloading the text, 
WeightsFinal=loadtxt('WeightsFinal.txt').reshape(LayerSize, 1)
Now y_out.shape=(3600,1) before it was y_out.shape = (3600, )
This resolves the issue! 

Mehdi Aslani

unread,
Apr 24, 2021, 7:54:10 AM4/24/21
to Machine Learning for Physicists
Exactly, this is the problem related to "rank 1" array which is not treated as a column vector nor a row vector.
you can read a much more complete answer here:
Reply all
Reply to author
Forward
0 new messages