Package org.python.core
Class PyArray
java.lang.Object
org.python.core.PyObject
org.python.core.PySequence
org.python.core.PyArray
- All Implemented Interfaces:
Serializable
,Cloneable
- Direct Known Subclasses:
PyArrayDerived
A wrapper class around native java arrays.
Instances of PyArray are created either by java functions or directly by the
jarray module.
See also the jarray module.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.python.core.PyObject
PyObject.ConversionException
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds (appends) two PyArrays together__findattr__
(String name) Finds the attribute.int
__len__()
Length of the array__repr__()
String representation of PyArray__tojava__
(Class c) Equivalent to the Jython __tojava__ method.void
Append new value x to the end of the array.static PyArray
static PyArray
Create a PyArray storing ctype types and being initialised with initialiser.void
array_append
(PyObject value) void
int
array_count
(PyObject value) void
array_extend
(PyObject iterable) void
array_fromlist
(PyObject obj) int
array_index
(PyObject value) void
array_insert
(int index, PyObject value) array_pop
(int i) void
array_remove
(PyObject value) void
void
void
void
byteswap()
"Byteswap" all items of the array.static Class
char2class
(char type) Converts a character code for the array type to a JavaClass
.clone()
Implementation of Cloneable interface.Return the number of occurrences of x in the array.void
Append items from iterable to the end of the array.void
Read count items (as machine values) from the file object f and append them to the end of the array.void
Append items from the list.void
fromstring
(String input) Appends items from the string, interpreting the string as an array of machine values (as if it had been read from a file using thefromfile()
method).getArray()
Return the internal Java array storage of the PyArray instanceint
Getter for the storage size of the array's type.Getter for the type code of the array.Return the smallest i such that i is the index of the first occurrence of value in the array.void
Insert a new item with value value in the array before position index.pop()
Removes the item with the index index from the array and returns it.pop
(int index) Removes the item with the index index from the array and returns it.void
Remove the first occurrence of value from the array.void
reverse()
Reverse the elements in the arrayvoid
Write all items (as machine values) to the file object f.tolist()
Convert the array to an ordinary list with the same items.tostring()
Convert the array to an array of machine values and return the string representation (the same sequence of bytes that would be written to a file by thetofile()
method.)static void
typeSetup
(PyObject dict, PyType.Newstyle marker) static PyArray
zeros
(int n, char typecode) static PyArray
Methods inherited from class org.python.core.PySequence
__delitem__, __delslice__, __eq__, __finditem__, __finditem__, __ge__, __getitem__, __getslice__, __gt__, __iter__, __le__, __lt__, __ne__, __nonzero__, __setitem__, __setitem__, __setslice__, isMappingType, isNumberType
Methods inherited from class org.python.core.PyObject
__abs__, __and__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __cmp__, __coerce__, __coerce_ex__, __complex__, __contains__, __delattr__, __delattr__, __delete__, __delitem__, __delslice__, __dir__, __div__, __divmod__, __findattr__, __finditem__, __float__, __floordiv__, __get__, __getattr__, __getattr__, __getitem__, __getnewargs__, __getslice__, __hash__, __hex__, __iadd__, __iand__, __idiv__, __idivmod__, __ifloordiv__, __ilshift__, __imod__, __imul__, __int__, __invert__, __ior__, __ipow__, __irshift__, __isub__, __iternext__, __itruediv__, __ixor__, __long__, __lshift__, __mod__, __mul__, __neg__, __not__, __oct__, __or__, __pos__, __pow__, __pow__, __radd__, __rand__, __rdiv__, __rdivmod__, __reduce__, __rfloordiv__, __rlshift__, __rmod__, __rmul__, __ror__, __rpow__, __rrshift__, __rshift__, __rsub__, __rtruediv__, __rxor__, __set__, __setattr__, __setattr__, __setitem__, __setslice__, __str__, __sub__, __truediv__, __unicode__, __xor__, _add, _and, _callextra, _cmp, _div, _divmod, _doget, _doget, _doset, _eq, _floordiv, _ge, _gt, _in, _is, _isnot, _jcall, _jcallexc, _jthrow, _le, _lshift, _lt, _mod, _mul, _ne, _notin, _or, _pow, _rshift, _sub, _truediv, _xor, asInt, asLong, asName, asString, asStringOrNull, delDict, delType, dispatch__init__, equals, fastGetClass, fastGetDict, getDict, getDoc, getType, hashCode, implementsDescrDelete, implementsDescrSet, invoke, invoke, invoke, invoke, invoke, isCallable, isDataDescr, isSequenceType, noAttributeError, readonlyAttributeError, safeRepr, setDict, setType, toString
-
Field Details
-
exposed_name
- See Also:
-
exposed_base
-
-
Constructor Details
-
PyArray
-
PyArray
-
PyArray
-
PyArray
-
-
Method Details
-
typeSetup
-
zeros
-
zeros
-
array
-
array
Create a PyArray storing ctype types and being initialised with initialiser.- Parameters:
init
- an initialiser for the array - can be PyString or PySequence (including PyArray) or iterable type.ctype
-Class
type of the elements stored in the array.- Returns:
- a new PyArray
-
__add__
Adds (appends) two PyArrays together -
__findattr__
Finds the attribute.- Overrides:
__findattr__
in classPyObject
- Parameters:
name
- the name of the attribute of interest- Returns:
- the value for the attribute of the specified name
- See Also:
-
__len__
public int __len__()Length of the array -
__repr__
String representation of PyArray -
__tojava__
Description copied from class:PyObject
Equivalent to the Jython __tojava__ method. Tries to coerce this object to an instance of the requested Java class. Returns the special objectPy.NoConversion
if thisPyObject
can not be converted to the desired Java class.- Overrides:
__tojava__
in classPySequence
- Parameters:
c
- target Class for the conversion- Returns:
- Java object converted to required class type if possible.
-
array_append
-
append
Append new value x to the end of the array.- Parameters:
value
- item to be appended to the array
-
array_byteswap
public void array_byteswap() -
byteswap
public void byteswap()"Byteswap" all items of the array. This is only supported for values which are 1, 2, 4, or 8 bytes in size; for other types of values, RuntimeError is raised. It is useful when reading data from a file written on a machine with a different byte order. -
clone
Implementation of Cloneable interface.- Returns:
- copy of current PyArray
-
char2class
Converts a character code for the array type to a JavaClass
. The following character codes and their native types are supported:
Type code native type z boolean
c char
b byte
h short
i int
l long
f float
d double
- Parameters:
type
- character code for the array type- Returns:
Class
of the native type- Throws:
PyIgnoreMethodTag
-
array_count
-
count
Return the number of occurrences of x in the array.- Parameters:
value
- instances of the value to be counted- Returns:
- number of time value was found in the array.
-
array_extend
-
extend
Append items from iterable to the end of the array. If iterable is another array, it must have exactly the same type code; if not, TypeError will be raised. If iterable is not an array, it must be iterable and its elements must be the right type to be appended to the array. Changed in version 2.4: Formerly, the argument could only be another array.- Parameters:
iterable
- iterable object used to extend the array
-
fromfile
Read count items (as machine values) from the file object f and append them to the end of the array. If less than count items are available, EOFError is raised, but the items that were available are still inserted into the array. f must be a real built-in file object; something else with a read() method won't do.- Parameters:
f
- Python builtin file object to retrieve datacount
- number of array elements to read
-
array_fromlist
-
fromlist
Append items from the list. This is equivalent to "for x in list: a.append(x)"except that if there is a type error, the array is unchanged.- Parameters:
obj
- input list object that will be appended to the array
-
fromstring
Appends items from the string, interpreting the string as an array of machine values (as if it had been read from a file using thefromfile()
method).- Parameters:
input
- string of bytes containing array data
-
getArray
Return the internal Java array storage of the PyArray instance- Returns:
- the
Array
store. - Throws:
PyIgnoreMethodTag
-
getItemsize
public int getItemsize()Getter for the storage size of the array's type. The sizes returned by this method represent the number of bytes used to store the type. In the case of streams, this is the number of bytes written to, or read from a stream. For memory this value is the minimum number of bytes required to store the type. This method is used by other methods to define read/write quanta from strings and streams. Values returned are:
Type Size boolean
1 byte
1 char
1 short
2 int
4 long
8 float
4 double
8 - Returns:
- number of bytes used to store array type.
-
getTypecode
Getter for the type code of the array.char2class
describes the possible type codes and their meaning.- Returns:
- single character type code for the array
- Throws:
PyIgnoreMethodTag
-
array_index
-
index
Return the smallest i such that i is the index of the first occurrence of value in the array.- Parameters:
value
- value to find the index of- Returns:
- index of the first occurance of value
-
array_insert
-
insert
Insert a new item with value value in the array before position index. Negative values are treated as being relative to the end of the array.- Parameters:
index
- insert positionvalue
- value to be inserted into array
-
array_pop
-
array_pop
-
pop
Removes the item with the index index from the array and returns it. The optional argument defaults to -1, so that by default the last item is removed and returned. -
pop
Removes the item with the index index from the array and returns it. The optional argument defaults to -1, so that by default the last item is removed and returned.- Parameters:
index
- array location to be popped from the array- Returns:
- array element popped from index
-
array_remove
-
remove
Remove the first occurrence of value from the array.- Parameters:
value
- array value to be removed
-
array_reverse
public void array_reverse() -
reverse
public void reverse()Reverse the elements in the array -
array_tofile
-
array_write
-
tofile
Write all items (as machine values) to the file object f.- Parameters:
f
- Python builtin file object to write data
-
array_tolist
-
tolist
Convert the array to an ordinary list with the same items.- Returns:
- array contents as a list
-
array_tostring
-
tostring
Convert the array to an array of machine values and return the string representation (the same sequence of bytes that would be written to a file by thetofile()
method.)
-