quippy.farray.FortranArray – Fortran one-based array indexing

quippy contains a FortranArray class and various utility functions for handling one-based array indexing.

class quippy.farray.FortranArray

Subclass of numpy.ndarray which uses Fortran-style one-based indexing.

The first element is numbered one rather than zero and trying to access element zero will raise an IndexError exception. Negative indices are unchanged; -1 still refers to the highest index along a dimension. Slices are also Fortran-style, i.e. inclusive on the second element so 1:2 includes the one-based elements 1 and 2, equivalent to a C-style slice of 0:2. The self.flat iterator is still indexed from zero.

all(axis=None, out=None)

One-based analogue of numpy.ndarray.all()

any(axis=None, out=None)

One-based analogue of numpy.ndarray.any()

argmax(axis=None, out=None)

Return one-based indices of the maximum values along the given axis of a.

Refer to numpy.ndarray.argmax for detailed documentation.

argmin(axis=None, out=None)

Return one-based indices of the minimum values along the given axis of a.

Refer to numpy.ndarray.argmax for detailed documentation.

argsort(axis=None, kind='quicksort', order=None)

Returns the indices that would sort this array.

Refer to numpy.argsort for full documentation.

col_iter()

Iterator for MxN arrays to return cols [...,i] for i=1,N one by one as Mx1 arrays.

cols

Iterator for MxN arrays to return cols [...,i] for i=1,N one by one as Mx1 arrays.

mapindices(indx)

Transform from Fortran-style one-based to C-style zero based indices.

indx can be any object that can be used to subscript an ndarray - scalar integer or slice, sequence of integers and slices or an ndarray of integer or boolean kind.

mean(axis=None, dtype=None, out=None)

One-based analogue of numpy.ndarray.mean()

nonzero()

Return the one-based indices of the elements of a which are not zero.

norm()

Return sqrt(norm2(self))

norm2()

Squared norm of a 1D or 2D array.

For a 1D array, returns dot(self,self) For a 2D array, must have shape (3,n). Returns array a where a[i] = dot(self[:,i],self[:,i])

put(indices, values, mode='raise')

Set a.flat[n] = values[n] for all n in indices.

Refer to numpy.put for full documentation.

row_iter()

Iterate over this FortranArray treating first dimension as fastest varying

rows

Iterate over this FortranArray treating first dimension as fastest varying

stripstrings()

Return contents as string (0- and 1-dimensional arrays) or array of strings with trailing spaces removed (2-dimensional arrays).

Raises ValueError if this FortranArray does not have a string datatype.

sum(axis=None, dtype=None, out=None)

One-based analogue of numpy.ndarray.sum()

take(indices, axis=None, out=None, mode='raise')

Return an array formed from the elements of a at the given one-based indices.

Refer to numpy.take for full documentation.

There are also some functions which operate on FortranArray instances:

quippy.farray.farray(seq, dtype=None)

Convert seq to a FortranArray with Fortran ordering.

>>> fa = farray([1,2,3])

A copy of the data in seq will be made if necessary.

quippy.farray.fenumerate(seq)

One-based equivalent of enumerate

quippy.farray.fidentity(n)

Return the n dimensional identity matrix as a FortranArray.

quippy.farray.frange(min, max=None, step=1)

Fortran equivalent of range() builtin.

Returns an iterator for integers from min to max inclusive, increasing by step each time.

>>> list(frange(3))
[1, 2, 3]
>>> list(frange(3,6,2))
[3, 5]
quippy.farray.fvar(seq)

Create one or more rank-0 instances of FortranArray and inject them into the global namespace.

This is a convenience function useful for making arrays to use as intent(in,out) arguments to a Fortran function. A single string argument causes variables with one-letter names to be created. The new arrays are also returned.

The following examples are equivalent:

>>> fvar("abc")
(FortranArray(0.0), FortranArray(0.0), FortranArray(0.0))
>>> a, b, c = fvar(['a','b','c'])
quippy.farray.fzeros(shape, dtype=<type 'float'>)

Create an empty FortranArray with Fortran ordering.

quippy.farray.padded_str_array(d, length)

Return FortranArray with shape (length, len(d)), filled with rows from d padded with spaces

quippy.farray.convert_farray_to_ndarray(func)

Decorator to convert all occurences of farray in arguments to ndarray. If result contains ndarray, they will be converted back to farray.

quippy.farray.convert_ndarray_to_farray(func)

Decorator to convert all occurences of ndarray in arguments to farray. If results contains farray, they will be converted back to ndarray.

quippy.farray.n2f(x)

Return x.view(FortranArray)

quippy.farray.f2n(x)

Return x.view(numpy.ndarray)

Previous topic

Core quippy module reference

Next topic

quippy.Atoms – store and manipulate atoms

This Page