Advertisement
skip420

choice

Jun 20th, 2022
782
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. # predicted outcome to chose outcome on war strategic positioning_duties
  2.  
  3.  
  4.  
  5.  
  6. # using randint()
  7. import random
  8.  
  9. import numpy as np
  10. import matplotlib.pyplot as plt
  11.  
  12. def lonely(p,X,r):
  13.     m = X.shape[1]
  14.     x0,y0 = p
  15.     x = y = np.arange(-r,r)
  16.     x = x + x0
  17.     y = y + y0
  18.  
  19.     u,v = np.meshgrid(x,y)
  20.  
  21.     u[u < 0] = 0
  22.     u[u >= m] = m-1
  23.     v[v < 0] = 0
  24.     v[v >= m] = m-1
  25.  
  26.     return not np.any(X[u[:],v[:]] > 0)
  27.  
  28. def generate_samples(m=2500,r=200,k=30):
  29.     # m = extent of sample domain
  30.     # r = minimum distance between points
  31.     # k = samples before rejection
  32.     active_list = []
  33.  
  34.     # step 0 - initialize n-d background grid
  35.     X = np.ones((m,m))*-1
  36.  
  37.     # step 1 - select initial sample
  38.     x0,y0 = np.random.randint(0,m), np.random.randint(0,m)
  39.     active_list.append((x0,y0))
  40.     X[active_list[0]] = 1
  41.  
  42.     # step 2 - iterate over active list
  43.     while active_list:
  44.         i = np.random.randint(0,len(active_list))
  45.         rad = np.random.rand(k)*r+r
  46.         theta = np.random.rand(k)*2*np.pi
  47.  
  48.         # get a list of random candidates within [r,2r] from the active point
  49.         candidates = np.round((rad*np.cos(theta)+active_list[i][0], rad*np.sin(theta)+active_list[i][1])).astype(np.int32).T
  50.  
  51.         # trim the list based on boundaries of the array
  52.         candidates = [(x,y) for x,y in candidates if x >= 0 and y >= 0 and x < m and y < m]
  53.  
  54.         for p in candidates:
  55.             if X[p] < 0 and lonely(p,X,r):
  56.                 X[p] = 1
  57.                 active_list.append(p)
  58.                 break
  59.         else:
  60.             del active_list[i]
  61.  
  62.     return X
  63.  
  64. X = generate_samples(2500, 200, 10)
  65. s = np.where(X>0)
  66. plt.plot(s[0],s[1],'.')
  67.  
  68. # open file
  69. with open("file1.txt", "r") as file:  
  70.     data = file.read()
  71.     words = data.split()
  72.      
  73.     # Generating a random number for word position
  74.     word_pos = random.randint(0, len(words)-1)
  75.     print("Position:", word_pos)
  76.     print("position here :", words[word_pos])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement