I have trouble declaring a two-dimensional list in Python. Below are two different matrices; A and R. When changing the content of a single cell I am successful in the R-matrix, but not so much in the A-matrix, as the value-input affect the entire column and not only the single cell.  Why does this happen? I would prefer the A-style of declaring the matrix.   n=6  A = [[0]*n]*n     R=[[0,0,0,0,0,0], [0,0,0,0,0,0], [0,0,0,0,0,0], [0,0,0,0,0,0], [0,0,0,0,0,0], [0,0,0,0,0,0]]  R[1][1]=5 A[1][1]=5  print(R) print(A)   The output from the two operations is:  [[0, 0, 0, 0, 0, 0], [0, 5, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]] [[0, 5, 0, 0, 0, 0], [0, 5, 0, 0, 0, 0], [0, 5, 0, 0, 0, 0], [0, 5, 0, 0, 0, 0], [0, 5, 0, 0, 0, 0], [0, 5, 0, 0, 0, 0]]
410
I needed to create a list of lists in Python, so I typed the following: my_list = [[1] * 4] * 3  The list looked like this: [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]    Then I changed one of the innermost values: my_list[0][0] = 5  Now my list looks like this: [[5, 1, 1, 1], [5, 1, 1, 1], [5, 1, 1, 1]]    which is not what I wanted or expected. Can someone please explain what's going on, and how to get around it?
55320
In the following question  the notation $c\in ]a,b[$ is used. What does this mean? I have never seen it before.
8035
So I'm complete stuck with something. I know it the following statements are true (or at least the seem to be from the results that I got from messing around with it a bit on MATLAB), but I don't understand why they are true or how to show so. Let $A$ be and $m$X$n$ matrix. Show that:  a) if $x \in N(A^TA)$ then $Ax$ is in both $R(A)$ and $N(A^T)$.   For this one I messed around with it with my own examples and I got $Ax=0$, therefore satisfing the statement, but I don't understand what's actually going on.   b) $N(A^TA)=N(A)$  again, makes sense when I see the results in MATLAB, but don't undestand why it works.  c) $A$ and $A^TA$ have the same rank  d) If $A$ has linearly independent columns, the $A^TA$ is nonsingular.  For the last two I have no idea on how to even start showing the relationship. I feel like I'm missing some crucial relationship between $A$ and $A^TA$, but I'm just not seeing it.   I would greatly appreciate any help of sugestions on how to show that these statements are true.   Thank you very much.
23996
I am a newbie to Python and have come across the following example in my book that is not explained very well. Here is my print out from the interpreter:  &gt;&gt;&gt; s = 'spam' &gt;&gt;&gt; s[:-1] 'spa'   Why does slicing with no beginning bound and a '-1' return every element except the last one? Is calling s[0:-1] logically the same as calling s[:-1]? They both return the same result. But I'm not sure what python is doing exactly. Any help would be greatly appreciated.
89126
I need to create a loop to answer part c of the following linear algebra question. I'm new to Matlab so this is extremely confusing. I'm not sure how to make a loop that "counts" from 0-25 in order to generate a new matrix for each value. If someone could help me out it'd be great.
24071
I'm trying to understand Python's approach to variable scope. In this example, why is f() able to alter the value of x, as perceived within main(), but not the value of n?  def f(n, x):     n = 2     x.append(4)     print('In f():', n, x)  def main():     n = 1     x = [0,1,2,3]     print('Before:', n, x)     f(n, x)     print('After: ', n, x)  main()   Output:  Before: 1 [0, 1, 2, 3] In f(): 2 [0, 1, 2, 3, 4] After:  1 [0, 1, 2, 3, 4]
103588
In Java, if I call List.toString(), it will automatically call the toString() method on each object inside the List. For example, if my list contains objects o1, o2, and o3, list.toString() would look something like this:  "[" + o1.toString() + ", " + o2.toString() + ", " + o3.toString() + "]"   Is there a way to get similar behavior in Python? I implemented a __str__() method in my class, but when I print out a list of objects, using:  print 'my list is %s'%(list)   it looks something like this:  [&lt;__main__.cell instance at 0x2a955e95f0&gt;, &lt;__main__.cell instance at 0x2a955e9638&gt;, &lt;__main__.cell instance at 0x2a955e9680&gt;]   how can I get python to call my __str__ automatically for each element inside the list (or dict for that matter)?
60990
I am attempting to create a plane and set the color; the following code throws an error at this line:    bpy.data.materials['RSgreen'].diffuse_color=(0,0,0)   the error is:  ValueError: bpy_struct: item.attr = val: sequences of dimension 0 should contain 4 items, not 3  which makes no sense to me; diffuse_color calls for 3 parameters in the .  bpy.ops.mesh.primitive_plane_add(size=4,enter_editmode=False,location=(-2,-2,0.01)) bpy.context.active_object.name='Plane2' bpy.ops.material.new() bpy.data.materials[1].name='RSgreen' bpy.data.materials['RSgreen'].diffuse_color=(0,0,0) bpy.context.object.data.materials.append(bpy.data.materials['RSgreen'])
90042
I have been thinking about this problem:  Suppose we have all $R$ by $C$ matrices, where the values are integers in $[1,n]$. Two matrices are equivalent under interchanging rows and columns. For example,   1 5     0 0       would be equal to itself and to  0 0 1 5   and would be equal to  0 0  5 1   and would be equal to   5 1 0 0   How many unique such matrices are there?  Any ideas how to go about it? Any help much appreciated!
14622
How to add label to index the rows and columns of the matrix ? because I want to number the line outside the matrix       \[     \begin{array}{lc}       \ Mat_{\varPhi to M} &amp; \left(\begin{array}{@{}ccccc@{}}             1 &amp; 1 &amp; 1 &amp; 1 &amp; 1 \\             0 &amp; 1 &amp; 0 &amp; 0 &amp; 1 \\             0 &amp; 0 &amp; 1 &amp; 0 &amp; 1 \\             0 &amp; 0 &amp; 0 &amp; 1 &amp; 1 \\             0 &amp; 0 &amp; 0 &amp; 0 &amp; 1               \end{array}\right) \\[15pt]     \end{array}     \]
117046
I am drawing a 3D array like the attached picture, which actually describes a multidimensional array. However, I can not put the name of the axis and take the value from the matrix like the attached picture.  This is the code that I have:  \documentclass[margin=5mm]{standalone} \usepackage{tikz} \usetikzlibrary{matrix,calc}  \begin{document} \begin{tikzpicture}[every node/.style={anchor=north east,fill=white,minimum width=1.4cm,minimum height=7mm}] \matrix (mA) [draw,matrix of math nodes] { (1,1,3) &amp; (1,1,3) &amp; (1,1,3) &amp; (1,1,3) \\ (1,1,3) &amp; (1,1,3) &amp; (1,1,3) &amp; (1,1,3) \\ (1,1,3) &amp; (1,1,3) &amp; (1,1,3) &amp; (1,1,3) \\ (1,1,3) &amp; (1,1,3) &amp; (1,1,3) &amp; (1,1,3) \\ };  \matrix (mB) [draw,matrix of math nodes] at ($(mA.south west)+(1.5,0.7)$) { (1,1,3) &amp; (1,1,3) &amp; (1,1,3) &amp; (1,1,3) \\ (1,1,3) &amp; (1,1,3) &amp; (1,1,3) &amp; (1,1,3) \\ (1,1,3) &amp; (1,1,3) &amp; (1,1,3) &amp; (1,1,3) \\ (1,1,3) &amp; (1,1,3) &amp; (1,1,3) &amp; (1,1,3) \\ };  \matrix (mC) [draw,matrix of math nodes] at ($(mB.south west)+(1.5,0.7)$) { (1,1,3) &amp; (1,1,3) &amp; (1,1,3) &amp; (1,1,3) \\ (1,1,3) &amp; (1,1,3) &amp; (1,1,3) &amp; (1,1,3) \\ (1,1,3) &amp; (1,1,3) &amp; (1,1,3) &amp; (1,1,3) \\ (1,1,3) &amp; (1,1,3) &amp; (1,1,3) &amp; (1,1,3) \\ };  \draw[dashed](mA.north east)--(mC.north east); \draw[dashed](mA.north west)--(mC.north west); \draw[dashed](mA.south east)--(mC.south east); \end{tikzpicture}   \end{document}
17043
I have a Python script which takes as input a list of integers, which I need to work with four integers at a time.  Unfortunately, I don't have control of the input, or I'd have it passed in as a list of four-element tuples.  Currently, I'm iterating over it this way: for i in range(0, len(ints), 4):     # dummy op for example code     foo += ints[i] * ints[i + 1] + ints[i + 2] * ints[i + 3]  It looks a lot like &quot;C-think&quot;, though, which makes me suspect there's a more pythonic way of dealing with this situation.  The list is discarded after iterating, so it needn't be preserved.  Perhaps something like this would be better? while ints:     foo += ints[0] * ints[1] + ints[2] * ints[3]     ints[0:4] = []  Still doesn't quite &quot;feel&quot; right, though.  :-/ Related question:
70618
So I was writing up a simple binary tree in Python and came across [...]  I don't believe this to be related to the Ellipsis object, more it seems to have something to do with an infinity loop (due to Python's shallow copy?). The source of this infinity loop and why it doesn't get expanded while expanding when accessed is something I'm completely lost to, however   &gt;&gt;&gt; a [[[[[], [], 8, 3], [[], [], 3, 2], 6, 3], [], 1, 4], [[], [], -4, 2], 0, 0] &gt;&gt;&gt; Keys(a)#With a+b [0, 1, 6, 8, 3, -4] &gt;&gt;&gt; Keys(a)#With [a,b] [8, [...], [...], 3, [...], [...], 6, [...], [...], 1, [...], [...], -4, [...], [...], 0, [...], [...]] &gt;&gt;&gt; Keys(a)[1]#?? [8, [...], [...], 3, [...], [...], 6, [...], [...], 1, [...], [...], -4, [...], [...], 0, [...], [...], 8, [...], [...], 3, [...], [...], 6, [...], [...], 1, [...], [...], -4, [...], [...], 0, [...], [...]]     Version using a+b  def Keys(x,y=[]):     if len(x):y+=[x[2]]+Keys(x[0],y)+Keys(x[1],y)#Though it seems I was using y=y[:]+, this actually outputs an ugly mess     return y   version using [a,b]  def Keys(x,y=[]):     if len(x):y+=[x[2],Keys(x[0],y),Keys(x[1],y)]     return y   So what exactly is [...]?
20774
I'm having troubling finding an example/proof that the following statement is true.     Row operations on a matrix A can change the linear   dependence relations among the rows of A.   Any tips on understanding this would be greatly appreciated.
28670
I have problems to show that if $A$ is a $2 \times 2$ matrix and if there exists some positive integer such that $A^{n}=0$ then $A^{2}=0$. I only showed that $A$ is a singular matrix but nothing else. Thanks any help will be appreciated.
107003
I'm working on a sparse matrix class that needs to use an array of LinkedList to store the values of a matrix. Each element of the array (i.e. each LinkedList) represents a row of the matrix. And, each element in the LinkedList array represents a column and the stored value.  In my class, I have a declaration of the array as:  private LinkedList&lt;IntegerNode&gt;[] myMatrix;   And, in my constructor for the SparseMatrix, I try to define:  myMatrix = new LinkedList&lt;IntegerNode&gt;[numRows];   The error I end up getting is     Cannot create a generic array of LinkedList&lt;IntegerNode&gt;.   So, I have two issues with this:   What am I doing wrong, and Why is the type acceptable in the declaration for the array if it can't be created?   IntegerNode is a class that I have created. And, all of my class files are packaged together.
95145
Is there an intelligent way to label (or name) columns in a matrix? I would like to have something like  \[M=\left[\begin{array}{c|cc} 1 &amp; 2 &amp; 3\\ 4 &amp; 5 &amp; 6 \end{array}\right],N=\left[\begin{array}{c|cc} 7 &amp; 8 &amp; 9\\ 10 &amp; 11 &amp; 12 \end{array}\right]\] \[A \ B \ C \ D \ E \ F\]   where A, B,..., F are the labels (or rather names) of the first, second, ..., sixth columns, respectively. What I want is to label A be exactly below the first column, label B be below the second column, etc., of course, nicely aligned. So far I have forced some extra spaces before the labels manually, and also experimented with the \phantom command.