In [1]:
%matplotlib inline
import numpy as np
import os
import matplotlib.pyplot as plt
plt.style.use('bmh')
In [2]:
x_min = 0
y_min = 0
x_max = 2 # x_max
y_max = 1 # y_max
# rectangular grid of points
# specify resolution
Nx = 10
Ny = 5
# specify limit of particle rectangle
particles_x_min = 0.9
particles_x_max = 1.1
particles_y_min = 0.4
particles_y_max = 0.6
# particles_x_min = 0
# particles_x_max = 2
# particles_y_min = 0
# particles_y_max = 1
paritcle_n = Nx*Ny
In [3]:
# create lists of all x and y positions
X = np.linspace(particles_x_min, particles_x_max, Nx, endpoint = False)
Y = np.linspace(particles_y_min, particles_y_max, Ny, endpoint = False)
In [4]:
X
Out[4]:
In [5]:
Y
Out[5]:
In [6]:
#XY = np.zeros((2, Ny, Nx))
# Use meshgrid to turn lists into rank 2 arrays
# of x and y positions
XY = np.meshgrid(X, Y)
XY
Out[6]:
In [9]:
np.shape(XY)
Out[9]:
In [36]:
particle_id = np.arange(paritcle_n)
particle_id
Out[36]:
In [37]:
particle_x = np.hstack(XY[:][0])
particle_x
Out[37]:
In [38]:
particle_y = np.hstack(XY[:][1])
particle_y
Out[38]:
In [10]:
# coordinates directly
x = np.linspace(particles_x_min, particles_x_max, paritcle_n , endpoint = False)
y = np.linspace(particles_y_min, particles_y_max, paritcle_n, endpoint = False)
x
Out[10]:
In [11]:
y
Out[11]:
In [13]:
# 2-rank array:
XY = [x, y]
XY
Out[13]:
In [14]:
np.array([x, y])
Out[14]:
In [65]:
plt.scatter(particle_x, particle_y)
plt.xlim(x_min, x_max)
plt.ylim(y_min, y_max)
Out[65]:
In [66]:
XY[0][:]
Out[66]:
In [67]:
XY[:][0]
Out[67]:
In [79]:
a = np.array([[1, 2], [3, 4]])
a
Out[79]:
In [78]:
a[0][:]
Out[78]:
In [80]:
a[:][0]
Out[80]:
In [86]:
a[:][1]
Out[86]:
In [94]:
a[0]
Out[94]:
In [100]:
particle_id[0::4]
Out[100]:
In [101]:
particle_id[1::4]
Out[101]:
In [102]:
particle_id[2::4]
Out[102]:
In [103]:
particle_id[3::4]
Out[103]:
In [104]:
particle_id[4::4]
Out[104]:
In [10]:
X
Out[10]:
In [12]:
b=[1,0,0,1]
In [13]:
b
Out[13]:
In [14]:
X[b]
Out[14]:
In [17]:
p = np.arange(10)
p
Out[17]:
In [29]:
b = np.ones(XY[0][:].size, dtype=bool)
In [31]:
b[10:] = 0
b
Out[31]:
In [21]:
p[b]
Out[21]:
In [22]:
XY
Out[22]:
In [26]:
XY[0][:]
Out[26]:
In [32]:
XY[0][b]
In [35]:
XY[0,:]
In [34]:
XY.shape
In [43]:
xy = np.array([particle_x, particle_y])
xy
Out[43]:
In [58]:
xy[0,:]
Out[58]:
In [59]:
xy[0,b]
Out[59]:
In [60]:
xy[0,:][b]
Out[60]:
In [61]:
xy[0,:]b
In [64]:
xy[:,b]
Out[64]:
In [65]:
xy[b,:]
In [ ]: