python,numpy,matrix,modeling , How to set first column to a constant value of an empty np.zeros numPy matrix?

## Question:

Tag: python,numpy,matrix,modeling

I'm working on setting some boundary conditions for a water table model, and I am able to set the entire first row to a constant value, but not the entire first column. I am using `np.zeros((11,1001))` to make an empty matrix. Does anyone know why I am successful at defining the first row, but not the first column? I have noted the line in question below.

``````import numpy as np

x = range(0,110,10)
time = range(0,5005,5)
xSize = len(x)
timeSize = len(time)

dx = 10
dt = 5
Sy = 0.1
k = 0.002

head[0:][0] = 16 # sets the first row to 16
head[0][0:] = 16 # DOESN'T set the first column to 16

for t in time:
for i in x[1:len(x)-1]:
``````

All you have to do is to change

``````head[0][0:]
``````

to

``````head[:,0]=16
``````

If you want to change the first row you can just do:

``````head[0,:] = 16
``````

EDIT:

Just in case you also wonder how you can change an arbitrary amount of values in an arbitrary row/column:

``````myArray = np.zeros((6,6))
``````

Now we set in row 2 3 values to 16:

``````myArray[2,1:4]=16.
array([[  0.,   0.,   0.,   0.,   0.,   0.],
[  0.,   0.,   0.,   0.,   0.,   0.],
[  0.,  16.,  16.,  16.,   0.,   0.],
[  0.,   0.,   0.,   0.,   0.,   0.],
[  0.,   0.,   0.,   0.,   0.,   0.],
[  0.,   0.,   0.,   0.,   0.,   0.]])
``````

The same works for columns:

``````myArray[2:5,4]=-4.
array([[  0.,   0.,   0.,   0.,   0.,   0.],
[  0.,   0.,   0.,   0.,   0.,   0.],
[  0.,  16.,  16.,  16.,  -4.,   0.],
[  0.,   0.,   0.,   0.,  -4.,   0.],
[  0.,   0.,   0.,   0.,  -4.,   0.],
[  0.,   0.,   0.,   0.,   0.,   0.]])
``````

And if you then also want to change certain values in e.g. two different rows at the same time you can do it like this:

``````myArray[[0,5],0:3]=10.
array([[ 10.,  10.,  10.,   0.,   0.,   0.],
[  0.,   0.,   0.,   0.,   0.,   0.],
[  0.,  16.,  16.,  16.,  -4.,   0.],
[  0.,   0.,   0.,   0.,  -4.,   0.],
[  0.,   0.,   0.,   0.,  -4.,   0.],
[ 10.,  10.,  10.,   0.,   0.,   0.]])
``````

# Related:

## Python Popen - wait vs communicate vs CalledProcessError

python,python-2.7,error-handling,popen
Continuing from my previous question I see that to get the error code of a process I spawned via Popen in python I have to call either wait() or communicate() (which can be used to access the Popen stdout and stderr attributes): app7z = '/path/to/7z.exe' command = [app7z, 'a', dstFile.temp,...