Learning Python
- I_HaRRiiSoN_I
- Retired Contributor
- Posts: 1626
- Joined: Jan 15, 2016
- Location: United Kingdom
Learning Python
Hey Squad!
so while ive been doing shitty work i have had to think about next steps in real life about work/career etc. I did a masters in Physics and at the moment and then had a data analysis job at an airline but felt much more 'safety & compliance' and based administration work really. i think i want to head down the data science with statistics route and so Ive decided to start off with learning python. I was just really wanting to know from people:
- Anybody here good with python?
- How did you get into python and why?
- Has it been worth it?
- any pointers for how i should go about learning this?
I will also want to get back into R studio at some point in the future and revisit statistics and do some further statistics learning but unsure whether i should try and learn this on a job, education institute, online courses, from a chunky textbook etc. The only kicker is that i still couldnt answer the question "what do you want to do in life" 100% confidently at the moment and I dont think i will ever. do we have an official coding thread yet for this kinda thing?
I have to admit i do want to spend a little less time with AoE as a result and am a little gutted by the amount of time wasted into AoE over lockdown casting/playing/casual playing and although it was fun i think I have missed a massive trick there while the whole country was busy doing F all.
cheers for any advice pointers
H
so while ive been doing shitty work i have had to think about next steps in real life about work/career etc. I did a masters in Physics and at the moment and then had a data analysis job at an airline but felt much more 'safety & compliance' and based administration work really. i think i want to head down the data science with statistics route and so Ive decided to start off with learning python. I was just really wanting to know from people:
- Anybody here good with python?
- How did you get into python and why?
- Has it been worth it?
- any pointers for how i should go about learning this?
I will also want to get back into R studio at some point in the future and revisit statistics and do some further statistics learning but unsure whether i should try and learn this on a job, education institute, online courses, from a chunky textbook etc. The only kicker is that i still couldnt answer the question "what do you want to do in life" 100% confidently at the moment and I dont think i will ever. do we have an official coding thread yet for this kinda thing?
I have to admit i do want to spend a little less time with AoE as a result and am a little gutted by the amount of time wasted into AoE over lockdown casting/playing/casual playing and although it was fun i think I have missed a massive trick there while the whole country was busy doing F all.
cheers for any advice pointers
H
Re: Learning Python
I first used it because someone wrote a library for it that did something very specific which I needed and the language I favor (C#) didn't have it as far as I could see.- How did you get into python and why?
Then from there I used it for misc scripting tasks and smaller hobby projects like a helper app for the game dominion (for balance purposes). I always found it fun to work with, and weak/dynamic typing can be convenient. But its main advantage I've found is the large collection of libraries written by the community that are often simply not there for other languages.
As for how I got into it, I just googled how Python implemented concepts I already knew. Learning programming is mostly about learning concepts for efficiently expressing the language of logic to a computer. Once you know the concepts it's fairly straightforward to switch between languages.
Yeah, I still use it frequently both at work and for hobby projects, and like working with it. But if I want to build something big and maintainable long-term, I think strongly typed languages are superior so I tend to avoid Python.- Has it been worth it?
For your purposes though it sounds like the way to go because it has a lot of great libraries for data analysis.
To learn programming it doesn't really matter which language you start with, and Python seems as good as any. I would recommend doing a basic tutorial and giving yourself small projects you are interested in. Then simply google how to do things as you go along. That's always been the only thing that worked for me, because it's fun. Doing assignments out of a book is less fun. And ultimately you learn programming by doing, by lots of trial and error, not so much by reading a book, although it helps to read about certain concepts before attempting to use them.- any pointers for how i should go about learning this?
Maybe you already have some ideas for projects? If so, mention them here and maybe I can give more specific advice about whether it's feasible for a beginner and/or what you'll need to learn.
Some resources: https://wiki.python.org/moin/BeginnersG ... rogrammers
CheckIO seems interesting, maybe that interactive way of learning would help keep you engaged. Haven't tried it myself.
Oh and be prepared to spend many hours on this. It's not something you learn in a day. This is why I would favor methods of learning that focus on keeping the fun in it. Try to think of projects to work on that you are actually interested in completing.
- harcha
- Gendarme
- Posts: 5141
- Joined: Jul 2, 2015
- ESO: hatamoto_samurai
Re: Learning Python
- Anybody here good with python?
Not me
- How did you get into python and why?
Some young professor taught it to us in my 2nd year of masters. The subject was completely unrelated, but he saw that it would be useless for us to teach that junk so he just decided to teach something useful - Python. He showed us the basics and how to apply those for gathering data from the web and doing simple operations for the purpose of data analysis.
- Has it been worth it?
Yeah, I actually used it to extract the data from long text files (logs) for my masters thesis practical part. Was pretty rad. Made that part much faster.
- any pointers for how i should go about learning this?
no idea mate
Not me
- How did you get into python and why?
Some young professor taught it to us in my 2nd year of masters. The subject was completely unrelated, but he saw that it would be useless for us to teach that junk so he just decided to teach something useful - Python. He showed us the basics and how to apply those for gathering data from the web and doing simple operations for the purpose of data analysis.
- Has it been worth it?
Yeah, I actually used it to extract the data from long text files (logs) for my masters thesis practical part. Was pretty rad. Made that part much faster.
- any pointers for how i should go about learning this?
no idea mate
POC wrote:Also I most likely know a whole lot more than you.
POC wrote:Also as an objective third party, and near 100% accuracy of giving correct information, I would say my opinions are more reliable than yours.
Re: Learning Python
- Anybody here good with python?
Nope, no interest either.
- How did you get into python and why?
I wanted to check out different languages during my bachelor's degree and also wanted to work in different paradigms. I created some small neat programs with it, as well as my final year thesis project based on convolutional neural networks.
- Has it been worth it?
Well I don't write python professionally so no.
- any pointers for how i should go about learning this?
It depends on the learner, some people learn better with videos I am a documentation man myself. I read official docs and take it from there, pretty old school but works for me. You should try both and pick what suits you.
Nope, no interest either.
- How did you get into python and why?
I wanted to check out different languages during my bachelor's degree and also wanted to work in different paradigms. I created some small neat programs with it, as well as my final year thesis project based on convolutional neural networks.
- Has it been worth it?
Well I don't write python professionally so no.
- any pointers for how i should go about learning this?
It depends on the learner, some people learn better with videos I am a documentation man myself. I read official docs and take it from there, pretty old school but works for me. You should try both and pick what suits you.
- Black_Duck
- Dragoon
- Posts: 347
- Joined: Mar 4, 2018
- ESO: Tom
- Location: London
- Clan: DUKC
Re: Learning Python
Are you starting programming from scratch or do you know other languages already?
Challenged_Macro wrote: Respect Mussolini guys,if hes triggered there is always a reason.
Mussolini wrote: I hope corona gets you, your family and all your fuckin relatives as you fuckin deserve it for being cocky
- I_HaRRiiSoN_I
- Retired Contributor
- Posts: 1626
- Joined: Jan 15, 2016
- Location: United Kingdom
Re: Learning Python
well i did a module in c language, bit of oracle/matlab but thats about it. The idea being python and R being the main languages
- Riotcoke
- Retired Contributor
- Posts: 4088
- Joined: May 7, 2019
- ESO: Riotcoke
- Location: Dorsetshire
- Clan: UwU
Re: Learning Python
@I_HaRRiiSoN_I Can always do a conversion masters in CS, can be done quite cheaply if you go to the same uni you did your undergrad in and is basically a fast track way.
twitch.tv/stangoesdeepTV
- Black_Duck
- Dragoon
- Posts: 347
- Joined: Mar 4, 2018
- ESO: Tom
- Location: London
- Clan: DUKC
Re: Learning Python
Python shouldnt be too hard to pick up in that case. You just need a project to work and youll just pick it up in no time.I_HaRRiiSoN_I wrote:well i did a module in c language, bit of oracle/matlab but thats about it. The idea being python and R being the main languages
Challenged_Macro wrote: Respect Mussolini guys,if hes triggered there is always a reason.
Mussolini wrote: I hope corona gets you, your family and all your fuckin relatives as you fuckin deserve it for being cocky
Re: Learning Python
Bump
hey just dicking around with Python trying to learn some of it. and does anyone know what the hell is going on here.
I am trying to multiply two matrices together and in order to do so, I am setting up a blank, empty matrix for the result. Doing so manually (the A matrix) gives me the correct answer. Trying to set up a matrix that is sized appropriately with a little code (the Z matrix) seems to bug out the code. Even though A and Z matrices are literally the same and even python says so.
hey just dicking around with Python trying to learn some of it. and does anyone know what the hell is going on here.
I am trying to multiply two matrices together and in order to do so, I am setting up a blank, empty matrix for the result. Doing so manually (the A matrix) gives me the correct answer. Trying to set up a matrix that is sized appropriately with a little code (the Z matrix) seems to bug out the code. Even though A and Z matrices are literally the same and even python says so.
- Attachments
-
- I_HaRRiiSoN_I
- Retired Contributor
- Posts: 1626
- Joined: Jan 15, 2016
- Location: United Kingdom
Re: Learning Python
Probably want to use numpy package, either the numpy array or numpy matrix. In base python the problem you have is {2,3,4}*3 ={2,3,4,2,3,4,2,3,4}
- harcha
- Gendarme
- Posts: 5141
- Joined: Jul 2, 2015
- ESO: hatamoto_samurai
Re: Learning Python
i'm but a noob, but does the i j k of the second matrix multiplication "for" statement begin restart counting or have they remained at some higher value since the first multiplication?
POC wrote:Also I most likely know a whole lot more than you.
POC wrote:Also as an objective third party, and near 100% accuracy of giving correct information, I would say my opinions are more reliable than yours.
Re: Learning Python
ohhh that's a really good thought.harcha wrote:i'm but a noob, but does the i j k of the second matrix multiplication "for" statement begin restart counting or have they remained at some higher value since the first multiplication?
I didn't think of that
however yeah it should reset because I tried to delete the lines of code for the A matrix and keep only Z and the result is pretty much the same
@I_HaRRiiSoN_I yeah I heard about the numpy pack. I'm going to import it once I need to crunch real numbers as opposed to little classroom examples, but just to get an understand for python coding, I wanted to do this without importing anything. thanks for the response though, how is your python coming along?
Re: Learning Python
I don't think that the I j and k used in the for loop are global values. I think they are local to the for loop and automatically get reset.harcha wrote:i'm but a noob, but does the i j k of the second matrix multiplication "for" statement begin restart counting or have they remained at some higher value since the first multiplication?
@iNcog idk why that's going wrong. I've only got one semester of python though.
Re: Learning Python
If the variables weren't reset you would get "index out of bounds" exceptions.
It looks like the way you're creating the Z array is causing this. It might be creating references to rather than copies of the first created array when you multiply it like that. Would be weird, but is the only possible cause I can see. The fact that the Z results in the 3 columns happen to be sums of the A results supports this.
EDIT:
>>> x = [0,0]
>>> y = 2 * [x]
>>> print(y)
[[0, 0], [0, 0]]
>>> y[0][0] += 1
>>> print(y)
[[1, 0], [1, 0]]
Both are changed because they both refer to the same value in memory.
It looks like the way you're creating the Z array is causing this. It might be creating references to rather than copies of the first created array when you multiply it like that. Would be weird, but is the only possible cause I can see. The fact that the Z results in the 3 columns happen to be sums of the A results supports this.
EDIT:
>>> x = [0,0]
>>> y = 2 * [x]
>>> print(y)
[[0, 0], [0, 0]]
>>> y[0][0] += 1
>>> print(y)
[[1, 0], [1, 0]]
Both are changed because they both refer to the same value in memory.
-
- Gendarme
- Posts: 5996
- Joined: Jun 4, 2019
Re: Learning Python
Code: Select all
i,j,k = 0 0 0
Z = [[1, 0, 0], [1, 0, 0], [1, 0, 0]]
i,j,k = 0 0 1
Z = [[1, 0, 0], [1, 0, 0], [1, 0, 0]]
i,j,k = 0 0 2
Z = [[1, 0, 0], [1, 0, 0], [1, 0, 0]]
i,j,k = 0 1 0
Z = [[1, 0, 0], [1, 0, 0], [1, 0, 0]]
i,j,k = 0 1 1
Z = [[1, 2, 0], [1, 2, 0], [1, 2, 0]]
i,j,k = 0 1 2
Z = [[1, 2, 0], [1, 2, 0], [1, 2, 0]]
i,j,k = 0 2 0
Z = [[1, 2, 0], [1, 2, 0], [1, 2, 0]]
i,j,k = 0 2 1
Z = [[1, 2, 0], [1, 2, 0], [1, 2, 0]]
i,j,k = 0 2 2
Z = [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
i,j,k = 1 0 0
Z = [[3, 2, 3], [3, 2, 3], [3, 2, 3]]
i,j,k = 1 0 1
Z = [[3, 2, 3], [3, 2, 3], [3, 2, 3]]
i,j,k = 1 0 2
Z = [[3, 2, 3], [3, 2, 3], [3, 2, 3]]
i,j,k = 1 1 0
Z = [[3, 2, 3], [3, 2, 3], [3, 2, 3]]
i,j,k = 1 1 1
Z = [[3, 6, 3], [3, 6, 3], [3, 6, 3]]
i,j,k = 1 1 2
Z = [[3, 6, 3], [3, 6, 3], [3, 6, 3]]
i,j,k = 1 2 0
Z = [[3, 6, 3], [3, 6, 3], [3, 6, 3]]
i,j,k = 1 2 1
Z = [[3, 6, 3], [3, 6, 3], [3, 6, 3]]
i,j,k = 1 2 2
Z = [[3, 6, 8], [3, 6, 8], [3, 6, 8]]
i,j,k = 2 0 0
Z = [[5, 6, 8], [5, 6, 8], [5, 6, 8]]
i,j,k = 2 0 1
Z = [[5, 6, 8], [5, 6, 8], [5, 6, 8]]
i,j,k = 2 0 2
Z = [[5, 6, 8], [5, 6, 8], [5, 6, 8]]
i,j,k = 2 1 0
Z = [[5, 6, 8], [5, 6, 8], [5, 6, 8]]
i,j,k = 2 1 1
Z = [[5, 12, 8], [5, 12, 8], [5, 12, 8]]
i,j,k = 2 1 2
Z = [[5, 12, 8], [5, 12, 8], [5, 12, 8]]
i,j,k = 2 2 0
Z = [[5, 12, 8], [5, 12, 8], [5, 12, 8]]
i,j,k = 2 2 1
Z = [[5, 12, 8], [5, 12, 8], [5, 12, 8]]
i,j,k = 2 2 2
Z = [[5, 12, 15], [5, 12, 15], [5, 12, 15]]
EDIT: Actually, why the fuck am I getting a different result? nvm I made a small error
Re: Learning Python
All object-oriented languages have their quirks when it comes to assigning/copying by value vs by reference. There are plenty of use cases for both approaches, but most languages seem to default to doing it by reference these days.
For example in C#:
The reason you would want to copy and assign things by reference becomes obvious when you start working with objects. For example say you have a game where you have a car object, and it has wheels. Say you have some bit of logic in your code that takes the front right wheel and tells it to deflate. You then want the car object that contains the wheel to also have a deflated front right wheel. You don't want the wheel to be stored separately, because then, if you deflate it, you have a deflated wheel in a vacuum but the car still has 4 good wheels. The wheel you're deflating should be a reference to the wheel in the car object, so that any changes you make to the wheel affect the car as well.
It's hard to explain that concept to someone who isn't used to working with objects in programming, but suffice to say this is not some weird bug in Python but intended behavior. It is a bit unintuitive in this case though.
For example in C#:
Code: Select all
public class Car {
public String Color { get; set; }
}
Car A = new Car { Color = "Red" };
Car B = A;
B.Color = "Blue";
Console.WriteLine(A.Color); // Prints "Blue"
It's hard to explain that concept to someone who isn't used to working with objects in programming, but suffice to say this is not some weird bug in Python but intended behavior. It is a bit unintuitive in this case though.
-
- Gendarme
- Posts: 5996
- Joined: Jun 4, 2019
Re: Learning Python
Of course I never said it was a weird bug. It's just annoying in python because these things happen more implicitly than for example in C. So sometimes unexpected and unintuitive things happen. Using the same code in C, it'd have been far easier to spot this mistake as the error needs to be explicitly coded like that.
Re: Learning Python
ohhhhh. so yeah it's just the same array three times?Goodspeed wrote:If the variables weren't reset you would get "index out of bounds" exceptions.
It looks like the way you're creating the Z array is causing this. It might be creating references to rather than copies of the first created array when you multiply it like that. Would be weird, but is the only possible cause I can see. The fact that the Z results in the 3 columns happen to be sums of the A results supports this.
EDIT:
>>> x = [0,0]
>>> y = 2 * [x]
>>> print(y)
[[0, 0], [0, 0]]
>>> y[0][0] += 1
>>> print(y)
[[1, 0], [1, 0]]
Both are changed because they both refer to the same value in memory.
tricky, but I think I get it. dimly. but then how to make it so that the three arrays are independent from one another? perhaps creating three small sub-arrays that are different from one another
my understanding of programming is obviously limited but I want to try to solve this
numpy, btw, makes everything super easy.
-
- Gendarme
- Posts: 5996
- Joined: Jun 4, 2019
Re: Learning Python
You could do something with append I suppose. First create an empty list and then append whatever you want it to eventually contain. That's what I tend to do with this stuff.iNcog wrote:ohhhhh. so yeah it's just the same array three times?Goodspeed wrote:If the variables weren't reset you would get "index out of bounds" exceptions.
It looks like the way you're creating the Z array is causing this. It might be creating references to rather than copies of the first created array when you multiply it like that. Would be weird, but is the only possible cause I can see. The fact that the Z results in the 3 columns happen to be sums of the A results supports this.
EDIT:
>>> x = [0,0]
>>> y = 2 * [x]
>>> print(y)
[[0, 0], [0, 0]]
>>> y[0][0] += 1
>>> print(y)
[[1, 0], [1, 0]]
Both are changed because they both refer to the same value in memory.
tricky, but I think I get it. dimly. but then how to make it so that the three arrays are independent from one another? perhaps creating three small sub-arrays that are different from one another
my understanding of programming is obviously limited but I want to try to solve this
numpy, btw, makes everything super easy.
(although I only code hot steaming crap in python that gives me a result asap even if it's achieved in a very shitty way, so there might be even better ways.
-
- Gendarme
- Posts: 5996
- Joined: Jun 4, 2019
Re: Learning Python
RefluxSemantic wrote:You could do something with append I suppose. First create an empty list and then append whatever you want it to eventually contain. That's what I tend to do with this stuff.iNcog wrote:ohhhhh. so yeah it's just the same array three times?Goodspeed wrote:If the variables weren't reset you would get "index out of bounds" exceptions.
It looks like the way you're creating the Z array is causing this. It might be creating references to rather than copies of the first created array when you multiply it like that. Would be weird, but is the only possible cause I can see. The fact that the Z results in the 3 columns happen to be sums of the A results supports this.
EDIT:
>>> x = [0,0]
>>> y = 2 * [x]
>>> print(y)
[[0, 0], [0, 0]]
>>> y[0][0] += 1
>>> print(y)
[[1, 0], [1, 0]]
Both are changed because they both refer to the same value in memory.
tricky, but I think I get it. dimly. but then how to make it so that the three arrays are independent from one another? perhaps creating three small sub-arrays that are different from one another
my understanding of programming is obviously limited but I want to try to solve this
numpy, btw, makes everything super easy.
(although I only code hot steaming crap in python that gives me a result asap even if it's achieved in a very shitty way, so there might be even better ways.
Code: Select all
X = [[1,2,3],[2,4,5],[2,6,7]]
Y = [[1,0,0],[0,1,0],[0,0,1]]
n = len(X)
m = len(Y[0])
zero = [0]
Z = [zero*m]*n
functioning_Z = []
for i in range(len(X)):
z = []
for i in range(len(Y[0])):
z.append(0)
functioning_Z.append(z)
print(functioning_Z)
A = [[0,0,0],[0,0,0],[0,0,0]]
print (A==Z)
for i in range(len(X)):
for j in range(len(Y[0])):
for k in range(len(Y)):
A[i][j] += X[i][k] * Y[k][j]
for i in range(len(X)):
for j in range(len(Y[0])):
for k in range(len(Y)):
Z[i][j] += X[i][k] * Y[k][j]
for i in range(len(X)):
for j in range(len(Y[0])):
for k in range(len(Y)):
functioning_Z[i][j] += X[i][k] * Y[k][j]
print("A = ", A)
print("Z = ", Z)
print("functioning_Z = ", functioning_Z)
Re: Learning Python
getting closer
Code: Select all
X = [[1,2,2],[2,4,5],[2,6,7]]
Y = [[1,0,0],[0,1,0],[0,0,1]]
n = len(X)
m = len(Y[0])
print("result matrix rows, n is: ", n)
print("result matrix columns, m is: ", m)
Z = []
z1 = []
z2 = []
z3 = []
for i in range(m):
z1.append(0)
z2.append(0)
z3.append(0)
Z.append(z1)
Z.append(z2)
Z.append(z3)
print(Z)
A = [[0,0,0],[0,0,0],[0,0,0]]
print ("A before operation is: "), print(A)
print("A and Z are the same matrix: ",A==Z)
for i in range(len(X)):
for j in range(len(Y[0])):
for k in range(len(Y)):
A[i][j] += X[i][k] * Y[k][j]
print("the A result matrix is: ")
for a in A:
print(a)
for i in range(len(X)):
for j in range(len(Y[0])):
for k in range(len(Y)):
Z[i][j] += X[i][k] * Y[k][j]
print("the Z result matrix is: ")
for z in Z:
print(z)
Re: Learning Python
Yeah I had that idea, though wasn't sure how to create an empty list that wasn't a reference without needing to manually do it. Gonna look at your code hereRefluxSemantic wrote:You could do something with append I suppose. First create an empty list and then append whatever you want it to eventually contain. That's what I tend to do with this stuff.iNcog wrote:ohhhhh. so yeah it's just the same array three times?Goodspeed wrote:If the variables weren't reset you would get "index out of bounds" exceptions.
It looks like the way you're creating the Z array is causing this. It might be creating references to rather than copies of the first created array when you multiply it like that. Would be weird, but is the only possible cause I can see. The fact that the Z results in the 3 columns happen to be sums of the A results supports this.
EDIT:
>>> x = [0,0]
>>> y = 2 * [x]
>>> print(y)
[[0, 0], [0, 0]]
>>> y[0][0] += 1
>>> print(y)
[[1, 0], [1, 0]]
Both are changed because they both refer to the same value in memory.
tricky, but I think I get it. dimly. but then how to make it so that the three arrays are independent from one another? perhaps creating three small sub-arrays that are different from one another
my understanding of programming is obviously limited but I want to try to solve this
numpy, btw, makes everything super easy.
(although I only code hot steaming crap in python that gives me a result asap even if it's achieved in a very shitty way, so there might be even better ways.
edit: nice one, it worked! that's pretty neat. I just need to understand what it is your code is doing. I indeed went with append but don't understand enough about that function to understand what it does
- Vinyanyérë
- Retired Contributor
- Posts: 1839
- Joined: Aug 22, 2016
- ESO: duolckrad, Kuvira
- Location: Outer Heaven
- Clan: 팀 하우스
Re: Learning Python
List comprehensions are one way; be warned that a side effect of using list comprehensions is that you turn into a giga chadiNcog wrote:ohhhhh. so yeah it's just the same array three times?Goodspeed wrote:If the variables weren't reset you would get "index out of bounds" exceptions.
It looks like the way you're creating the Z array is causing this. It might be creating references to rather than copies of the first created array when you multiply it like that. Would be weird, but is the only possible cause I can see. The fact that the Z results in the 3 columns happen to be sums of the A results supports this.
EDIT:
>>> x = [0,0]
>>> y = 2 * [x]
>>> print(y)
[[0, 0], [0, 0]]
>>> y[0][0] += 1
>>> print(y)
[[1, 0], [1, 0]]
Both are changed because they both refer to the same value in memory.
tricky, but I think I get it. dimly. but then how to make it so that the three arrays are independent from one another? perhaps creating three small sub-arrays that are different from one another
my understanding of programming is obviously limited but I want to try to solve this
numpy, btw, makes everything super easy.
Code: Select all
>>> x = [0 for _ in range(4)]
>>> x
[0, 0, 0, 0]
>>> x[2] = 7
>>> x
[0, 0, 7, 0]
>>> y = [[0 for m in range(3)] for n in range(2)]
>>> y
[[0, 0, 0], [0, 0, 0]]
duck
imo
imo
-
- Gendarme
- Posts: 5996
- Joined: Jun 4, 2019
Re: Learning Python
This method is very chad indeed.Vinyanyérë wrote:List comprehensions are one way; be warned that a side effect of using list comprehensions is that you turn into a giga chadiNcog wrote:ohhhhh. so yeah it's just the same array three times?Goodspeed wrote:If the variables weren't reset you would get "index out of bounds" exceptions.
It looks like the way you're creating the Z array is causing this. It might be creating references to rather than copies of the first created array when you multiply it like that. Would be weird, but is the only possible cause I can see. The fact that the Z results in the 3 columns happen to be sums of the A results supports this.
EDIT:
>>> x = [0,0]
>>> y = 2 * [x]
>>> print(y)
[[0, 0], [0, 0]]
>>> y[0][0] += 1
>>> print(y)
[[1, 0], [1, 0]]
Both are changed because they both refer to the same value in memory.
tricky, but I think I get it. dimly. but then how to make it so that the three arrays are independent from one another? perhaps creating three small sub-arrays that are different from one another
my understanding of programming is obviously limited but I want to try to solve this
numpy, btw, makes everything super easy.
Code: Select all
>>> x = [0 for _ in range(4)]
>>> x
[0, 0, 0, 0]
>>> x[2] = 7
>>> x
[0, 0, 7, 0]
>>> y = [[0 for m in range(3)] for n in range(2)]
>>> y
[[0, 0, 0], [0, 0, 0]]
Who is online
Users browsing this forum: No registered users and 18 guests