3.10 PND class

The PND class is rather similar to the P0D, but now data are stored in a multidimensional array. This class does not have also any graphical attributes, since it was mainly designed for data manipulations. To plot data as a histogram, one should convert a raw or column to a P0D object.

To construct a PND and add some values, use:

>>> from jhplot import PND
>>>
>>> p0=PND("example")           # build a PND object
>>> p0.add([1,2,3])             # append some values
>>> p0.add([2,3,4])
>>> p0.add([2,3,4,3,4])         # append more columns
>>> p0.add([2,3])               # append less  columns
>>> p0.add(P0D p0d)             # append P0D object
>>> p0.set(i,[1,2,3])           # set (replace) at position i
>>> p0.set(i,P0D p0d)           # set (replace) P0D object at position i
>>> # here are fast methods to fill P0D:
>>> array=p0.getArray(index)     # get array[] at raw index 
>>> p0.setArray(array[][])       # fill with numbers from an array
>>> p0.clear()                   # clear
>>> p0.size()                    # get size (number of rows)
>>> m=p0.getDimension()          # get dimension
>>> m=get(row,column)            # get a value at row and column
>>> p0=PND("example",dimension,file) # build a PND object from a file
It should be noted that the dimension for each row is not fixed, i.e. one can add arbitrary length array. The method p0.getDimension() returns the dimension of the last appended array. If the dimension is different for each row, one could expect problems for some methods which are based on two-dimensional arrays with fixed number of rows and columns. So, try to avoid the use of rows with different length.

As before, avoid operations with primitive types like add() or set() to make a program faster. All other classes are rather similar to the P0D. For example, to write data to a file, use:

>>> p0.toFile("file name") # output to a file
>>> p0.write("file")       # as before
>>> p0=p0.read("file")     # read from a file

One can easily get an array from a certain column or a row in form of P0D using the following methods:

>>> p0.getRaw(index)    # get a row at index as P0D
>>> p0.getColumn(index) # get a column at index as P0D

Once P0D is obtained, one can make a histogram using P0D method getH1D(). Look at the API to learn more about the PND methods.