[Numpy-discussion] Using 2-D arrays in Numeric Python (numpy)
Sat Oct 11 00:26:39 CDT 2008
On Sat, Oct 11, 2008 at 2:16 PM, Linda Seltzer
> I would appreciate it if someone could answer my question without
> referring to subjects such as APIs and interfaces, since I am only
> concerned with a mathematical application at this time.
> In most tutorials, array examples are of the form:
> a = array([1, 2, 3], [4, 5, 6] )
> The problem with this is that I have an array of size 256 x 256, and I
> have had applications with 3-d arrays of size 128x128x128. In video, you
> can arrays such as 640x480, etc. So filling in the value of each element
> is not practical. I wish that tutorials provided real world examples.
> I would appreciate it if someone could give me the actual statements
> needed to define and initialize a 2-D array of size NxN, where N can be
> any large number, where the initial values of the array elements are all
> zeros, but will be changed by the program.
> In Matlab, this is done as a = zeros(256,256). If I try this in python,
> it won't let the program overwrite the zeros.
In numpy it's
import numpy as npy
a = npy.zeros((256,256))
a[0,0] = 1.0
a[200,123] = -42.0
I think you were just missing the extra parentheses in the numpy
version of "zeros"
More information about the Numpy-discussion