Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped over it's main diagonal, switching the row and column indices of the matrix. Example Input: [[1,2,3],[4,5,6]] Output: [[1,4],[2,5],[3,6]] my code: def transpose( A):     length = len(A)     width = len(A[0])     res = [[0] * length] * width     for i in range(length):         for j in range(width):             res[j][i] = A[i][j]     return res        transpose([[1,2,3],[4,5,6]])  my code's result : [[3, 6], [3, 6], [3, 6]] I track in the double loop, every time the res is updated, the value of a column is updated. def transpose( A):     length = len(A)     width = len(A[0])     res = [[0] * length] * width     for i in range(length):         for j in range(width):             res[j][i] = A[i][j]             print(i,j,'-&gt;',j,i)             print(res)     return res        transpose([[1,2,3],[4,5,6]])  The output information is as follows: 0 0 -&gt; 0 0 [[1, 0], [1, 0], [1, 0]] 0 1 -&gt; 1 0 [[2, 0], [2, 0], [2, 0]] 0 2 -&gt; 2 0 [[3, 0], [3, 0], [3, 0]] 1 0 -&gt; 0 1 [[3, 4], [3, 4], [3, 4]] 1 1 -&gt; 1 1 [[3, 5], [3, 5], [3, 5]] 1 2 -&gt; 2 1 [[3, 6], [3, 6], [3, 6]]  But the following code gets the correct result： def transpose( A):         length, width = len(A), len(A[0])         res = [[0] * length for _ in range(width)]         for r, row in enumerate(A):             for c, val in enumerate(row):                 res[c][r] = val         return res  transpose([[1,2,3],[4,5,6]])  It's confusing!Is there any difference between the two ways of loop？ Is it caused by the underlying code optimization during compilation?
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?
What was Mr. Anderson (Neo) selling on discs to Choi? A inequality proposed at Zhautykov Olympiad 2008 An inequality proposed at Zhautykov Olympiad 2008.     Let be $a,b,c &gt;0$ with $abc=1$. Prove that:    $$\sum_{\mathrm{cyc}}{\frac{1}{(a+b)b}} \geq \frac{3}{2}.$$   Set $a=\frac{x}{y}$, $b=\frac{y}{z}$, $c=\frac{z}{x}$.   Our inequality becomes: $$\sum_{\mathrm{cyc}}{\frac{z^2}{zx+y^2}} \geq \frac{3}{2}.$$  Now we use that: $z^2+x^2 \geq 2zx.$ $$\sum_{\mathrm{cyc}}{\frac{z^2}{zx+y^2}} \geq \sum_{\mathrm{cyc}}{\frac{2z^2}{z^2+x^2+2y^2}} \geq \frac{3}{2}.$$  Now applying Cauchy-Schwarz we obtain the desired result.  What I wrote can be found on this link: . But now, I don't know how to apply Cauchy-Schwarz.   Thanks:) Why does the question's closed status disappear when clicking to load a new edit? I've come across a small issue which occurs when a question has been closed but the question itself or one of its answers are being edited.  Steps to reproduce:   Visit a closed question. (even closed years ago)   In a different tab or browser, edit the question or one of its answers. "an edit has been made to this post; click to load" message will appear above the edited post in the first tab/browser, click it. The .question-status div becomes hidden, which includes the closed notice below a question and, for a duplicate-closed question, the list of duplicates above the question body. This gives the appearance that the question is no longer closed (until you refresh).   Some screenshots:                I know it isn't common/important but it did confuse me when looking at a particularly bad question - I thought it had been reopened.   Is this an intentional feature? If so, what was the thinking behind it?    Another example  Before    After While finding escape velocity, does human mass counts as the mass of Earth? Escape velocity depends upon the mass of earth. my doubt is whether human mass adds into it or not? If it add then Earth's escape velocity would be increasing! su command + authentication failure Do film industries outside India use intervals/Intermission? Prove that If $m'$ is a common multiple of $s$ and $t$, then $m | m'$. Here $m$ is the LCM of $s$ and $t$.    Although the statement is intuitively clear to me I don't know how to prove. What are the browser and resolution stats for SO users? Google Analytics (and some log parsers) will give you breakdowns on usage of different browsers, different versions of those browsers and screen resolutions.  I'm just curious to know what SO users user. Any chance we could get some stats on that? You may view this as commercial information, in which case I understand (as i'ts relevant to marketing/advertising).  I'm also curious to know the # of users who read and/or post from mobile devices and if so which ones.  UPDATE: Please refrain from personal anecdotes ("I use..."). I'm interested in actual usage, not personal stories. Thankyou. Limits of trig functions I am trying to restore a database with the following command:  $ sudo -u postgres pg_restore -C -d dvdrental dvdrental.tar  [sudo] password for t:    However, I am receiving the following error message:      could not change directory to "/home/t/mydata/.../relation model/SQL/implementations/Implementations, i.e. relational database management systems/postgreSQL/general/web/postgresqltutorial/databases": Permission denied      pg_restore: [archiver] could not open input file "dvdrental.tar": No such file or directory   I was wondering why I can't change directory to the current directory with permission denied?  File permission bits are:   -rw-rw-r-- 1 t t 2838016 May 26  2013 dvdrental.tar   Is it because one of its ancestry directory is not both readable and executable by any one?  The file has  many ancestry directories, and how can I verify that? Soft version of the maximum function? In the book Deep Learning, it says the softmax function is de facto a soft argmax function, and the corresponding soft version of the maximum function is $$\text{softmax} (z)^T z$$ How to understand the latter? Why is my ASCII art all wonky? Nothing looks right in the ASCII art.  It looks wrong and nothing is proportional, how do I fix this? I have tried fiddling with my font size, but nothing still looks right! I've made some high resolution pixel art in PS by drawing it down at the pixel level and then increasing the image size with the nearest neighbor setting to keep it crisp. In the web browser, however, I need to display these images as icons with a dynamic size, so I can't just size the images correctly to begin with, and the broswer seems to blur the images when rendering them smaller, while vector images seem to stay more crisp as they shrink.   So I'm wondering if there's a way to convert the pixel art neatly into vector. I'm aware of the trace function in illustrator, but it seems to do a rough job iirc. Today I upgraded to the Creators Update by running setup from the ISO mounted locally. When I got back to my computer I opened Task Manager and saw my memory usage was a lot higher than it was previously (it's now almost 6GB memory usage at idle after logging in instead of 2-3GB with the previous Windows build) - the processes tab revealed that there were upwards of 60 different instances of svchost.exe running. This 6GB figure is just for process memory - not including memory used for caching or "standby".  I ran tasklist /svc to get a listing of which services were in which processes and it lists almost every svchost.exe instance as only having one running service contained within (with the exception of a handful of instances that are running a few system services).  Here's  my output:  Image Name                     PID Services ========================= ======== ============================================ System Idle Process              0 N/A System                           4 N/A smss.exe                       440 N/A csrss.exe                      612 N/A wininit.exe                    700 N/A csrss.exe                      708 N/A services.exe                   776 N/A lsass.exe                      784 KeyIso, Netlogon, SamSs, VaultSvc svchost.exe                    888 PlugPlay svchost.exe                    908 BrokerInfrastructure, DcomLaunch, Power,                                    SystemEventsBroker fontdrvhost.exe                936 N/A svchost.exe                   1000 RpcEptMapper, RpcSs svchost.exe                    104 LSM winlogon.exe                   544 N/A fontdrvhost.exe                420 N/A svchost.exe                   1072 DeviceInstall dwm.exe                       1136 N/A svchost.exe                   1164 BFE, CoreMessagingRegistrar, MpsSvc svchost.exe                   1424 lmhosts svchost.exe                   1432 W32Time svchost.exe                   1440 nsi svchost.exe                   1448 wudfsvc svchost.exe                   1528 hidserv svchost.exe                   1628 Dhcp svchost.exe                   1716 Dnscache svchost.exe                   1748 EventLog WUDFHost.exe                  1792 N/A svchost.exe                   1908 TimeBrokerSvc svchost.exe                   1952 NlaSvc NVDisplay.Container.exe       1968 NVDisplay.ContainerLocalSystem svchost.exe                   1324 Themes svchost.exe                   1596 ProfSvc svchost.exe                   1944 EventSystem svchost.exe                   1052 netprofm svchost.exe                   2116 StateRepository svchost.exe                   2256 SENS svchost.exe                   2296 AudioEndpointBuilder svchost.exe                   2304 FontCache (etc)...   I know you can configure individual services to run in their own instance of svc with the sc config &lt;serviceName&gt; type= own command, but to my knowledge I've never run this command.  I took a quick look at Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services and it looks like the Type key values for most of these services is missing the flag bit at 0x10 which controls if a service runs in its own svchost.exe instance or not. I wonder what could have effected this change.  Has anyone else observed this behaviour before or after installing Windows 10 Creators Update? If it is a default configuration change, will it have any implications on system performance or stability?  I suspect it will increase system stability because if a service crashes it won't bring down other services - but this comes at a massive cost of RAM - but I've never experienced a service crashing on me - or at least ever noticed it (instead the worst problem I've had is with wuauserv consuming 100% CPU for hours on end - and that's not a problem process isolation will solve).  (I just noticed: they finally added an address bar to the Registry Editor!) Change all file type associations from one program to another Let $P\in\mathbb{R}[X]$ be a positive polynomial.  I want to show that there exists $A,B\in\mathbb{R}[X]$ so that $P=A^2+B^2$    $\displaystyle P=a\prod_{k=0}^q(x-a_k)\prod_{k=0}^{2p}(x-b_k)=a\prod_{k=0}^q(x-a_k)\prod_{k=0}^p(x^2-2\Re(b_k)+|b_k|^2)$ where $a$ is the leading coefficient, $a_k$ are the real rooks, $b_k$ are the complex roots.  What can i do now ? I know that the identity $(a^2+b^2)(c^2+d^2)=(ac-bd)^2+(ad+bc)^2$ should come in handy, but I can't figure out :  1) How to show that the product real roots is a square  2) How to use the above identity for the complex roots.  If I can solve those two points, then I can solve the problem. book recommendation on functional analysis Reset the password in Ubuntu / Linux Bash in Windows I have installed Linux Bash on Windows 10 (available from Microsoft), but I've forgotten my password.  I've searched for a solution but I only find suggestions that involve doing something before the system boots, like accessing recovery mode, but that will not work in this case as this Ubuntu is just an application within a Windows system and doesn't have its own boot process.  How can I reset my password? How can I get rid of those little white dots? I am using Blender 2.70a. My Alt + Tab menu looks and works oddly