Note that there are some explanatory texts on larger screens.

plurals
  1. POPython List Function
    text
    copied!<p>I have a list called network which needs to be modified by the use of a function. The list contains 100 elements, of which each is at random +1 or -1. This list has to be modified in a way so that every time a function runs, it modifies an element in a copy of network. I then need to graph these lists on a graph. </p> <p>My code is as follows:</p> <pre><code>import math import random import numpy as np #Generate network elements network=[] for x in range(0,100): network.append(random.choice([-1,1])) #Generate Matrix matrix=np.ones((100,100)) p=np.random.permutation(100) matrix[p[:10]]=1 matrix[p[:10]]=-1 #Set diagonal values to zero matrix[np.diag_indices_from(matrix)]=0 #THIS IS THE FUNCTION THAT WILL BE MODIFYING AN ELEMENT, i, IN NETWORK. def new_sum(i): hi=np.sum(np.dot(matrix[i][:100],network[:100])) if hi&gt;0: hi==1 if hi&lt;0: hi==-1 return hi """HERE IS WHERE I NEED HELP. I NEED TO HAVE THIS FUNCTION RUN AT RANDOM ON ANY ELEMENT IN NETWORK. WHEN IT RUNS, I NEED TO COPY NETWORK AS A NEW LIST AND HAVE hi REPLACE THE CORRESPONDING INDEX, i, IN THE COPIED LIST. THE PROBLEM IS THAT I NEED TO HAVE THIS FUNCTION RUN 300 TIMES, AND EVERYTIME IT RUNS, I NEED TO COPY NETWORK AS A NEW LIST AND HAVE hi REPLACE THE CORRESPONDING INDEX, i, IN THE COPIED LIST. HERE IS CODE: """ def new_function(value): for i in range(0,value): new_list=network[:] new_sum(i)= x new_list[i]=x return new_list def plot_data(ax, data, xval): N:len(data) uniqdata, idx=np.unique(data, return_inverse=True) ax.scatter(np.ones(N)*xval,np.arange(1,N+1),s=50,c=cmap[idx]) cmap = np.array([(1,0,0),(0,1,0)]) fig, ax=plt.subplots </code></pre> <p>I then have to graph the 300 lists that need to be created, where each list is the argument, <code>data</code>, in the function <code>plot_data</code>. How do I do this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload