Ameba Ownd

アプリで簡単、無料ホームページ作成

Pyarray_type pyarg_parsetuple

2022.01.14 16:28


->>>> Click Here to Download <<<<<<<-





















On failure, NULL is returned and an exception is set. The C-based names can be used:. The object will be converted to the desired type only if it can be done without losing precision.


Otherwise NULL will be returned and an error raised. The memory model for an ndarray admits arbitrary strides in each dimension to advance to the next element of the array. Often, however, you need to interface with code that expects a C-contiguous or a Fortran-contiguous memory layout. In addition, an ndarray can be misaligned the address of an element is not at an integral multiple of the size of the element which can cause your program to crash or at least work more slowly if you try and dereference a pointer into the array data.


The requirements flag allows specification of what kind of array is acceptable. If the object passed in does not satisfy this requirements then a copy is made so that thre returned object will satisfy the requirements.


This flag allows specification of the desired properties of the returned array object. All of the flags are explained in the detailed API chapter. This combination of flags is useful for arrays that must be in C-contiguous order and aligned.


These kinds of arrays are usually input arrays for some algorithm. This combination of flags is useful to specify an array that is in C-contiguous order, is aligned, and can be written to as well. Such an array is usually returned as output although normally such output arrays are created from scratch. This combination of flags is useful to specify an array that will be used for both input and output.


This will delete the array without causing the contents to be copied back into the original array. Whether or not an array is byte-swapped is determined by the data-type of the array. There is also no way to get a byte-swapped array from this routine. Quite often new arrays must be created from within extension-module code. Perhaps only a temporary array is needed to hold an intermediate calculation.


Whatever the need there are simple ways to get an ndarray object of whatever data-type is needed. All array creation functions go through this heavily re-used code. Because of its flexibility, it can be somewhat confusing to use.


As a result, simpler forms exist that are easier to use. This function allocates new memory and places it in an ndarray with nd dimensions whose shape is determined by the array of at least nd items pointed to by dims.


Sometimes, you want to wrap memory allocated elsewhere into an ndarray object for downstream use. This routine makes it straightforward to do that. A new reference to an ndarray is returned, but the ndarray will not own its data. When this ndarray is deallocated, the pointer will not be freed. You should ensure that the provided memory is not freed while the returned array is in existence. The easiest way to handle this is if data comes from another reference-counted Python object.


Using this function, the example from the last section becomes. The first argument specifies the number of dimensions, the second one the length of each dimension, and the third one the element data type see the table in the section "Element data types". The array that is returned is contiguous, but the contents of its data space are undefined. There is a second function which permits the creation of an array object that uses a given memory block for its data space:.


The fourth argument is a pointer to the memory block that is to be used as the array's data space. It is the caller's responsibility to ensure that this memory block is not freed before the array object is destroyed. With few exceptions such as the creation of a temporary array object to which no reference is passed to other functions , this means that the memory block may never be freed, because the lifetime of Python objects are difficult to predict.


Nevertheless, this function can be useful in special cases, for example for providing Python access to arrays in Fortran common blocks. Array objects can of course be passed out of a C function just like any other object.


However, as has been mentioned before, care should be taken not to return zero-dimensional arrays unless the receiver is known to be prepared to handle them. An equivalent Python scalar object should be returned instead. To facilitate this step, NumPy provides a special function. It takes three arguments: a scalar prefactor, the matrix a two-dimensional array , and the vector a one-dimensional array.


The return value is a one-dimensional array. The input values are checked for consistency. In addition to providing an illustration of the functions explained above, this example also demonstrates how a Fortran routine can be integrated into Python. Unfortunately, mixing Fortran and C code involves machine-specific peculiarities. In this example, two assumptions have been made:. So here is the code:. Nevertheless, it is a good habit to always use this function; its performance cost is practically zero.


In this case the resulting C string may contain embedded NUL bytes. The result is stored into two C variables, the first one a pointer to a C string, the second one its length. The string may contain embedded null bytes. This format converts a bytes-like object to a C pointer to a character string; it does not accept Unicode objects.


The bytes buffer must not contain embedded null bytes; if it does, a ValueError exception is raised. This is the recommended way to accept binary data. Requires that the Python object is a bytes object, without attempting any conversion.


Raises TypeError if the object is not a bytes object. Requires that the Python object is a bytearray object, without attempting any conversion. Raises TypeError if the object is not a bytearray object. Deprecated since version 3. This variant on u stores into two C variables, the first one a pointer to a Unicode data buffer, the second one its length. This variant allows null code points. Requires that the Python object is a Unicode object, without attempting any conversion.


Raises TypeError if the object is not a Unicode object. This format accepts any object which implements the read-write buffer interface. The buffer may contain embedded null bytes. This variant on s is used for encoding Unicode into a character buffer. It only works for encoded data without embedded NUL bytes. This format requires two arguments. An exception is raised if the named encoding is not known to Python.


The text will be encoded in the encoding specified by the first argument. Same as es except that byte string objects are passed through without recoding them. Instead, the implementation assumes that the byte string object uses the encoding passed in as parameter.


Unlike the es format, this variant allows input data which contains NUL characters. It requires three arguments. The third argument must be a pointer to an integer; the referenced integer will be set to the number of bytes in the output buffer. It will then copy the encoded data into the buffer and NUL-terminate it. If the buffer is not large enough, a ValueError will be set. Convert a nonnegative Python integer to an unsigned tiny int, stored in a C unsigned char.


Convert a Python integer to a tiny int without overflow checking, stored in a C unsigned char. Convert a Python integer to a C unsigned short int , without overflow checking. Convert a Python integer to a C unsigned int , without overflow checking. Convert a Python integer to a C unsigned long without overflow checking. It should return a -1 on error and 0 otherwise.


These functions and macros provide easy access to elements of the ndarray from C. These work for all arrays. You may need to take care when accessing the data in the array, however, if it is not in machine byte-order, misaligned, or not writeable. If you wish to handle all types of arrays, the copyswap function for each type is useful for handling misbehaved arrays.


Some platforms e. Solaris do not like misaligned data and will crash if you de-reference a misaligned pointer. Other platforms e. You may want to typecast the returned pointer to the data type of the ndarray. Quick, inline access to the element at the given coordinates in the ndarray, obj , which must have respectively 1, 2, 3, or 4 dimensions this is not checked. This function steals a reference to descr.


This is the main array creation function. Most new arrays are created with this flexible function. The array has nd dimensions, described by dims. The data-type descriptor of the new array is descr.


If data is NULL , then new unitinialized memory will be allocated and flags can be non-zero to indicate a Fortran-style contiguous array. In addition, if data is non-NULL, then strides can also be provided. Any provided dims and strides are copied into newly allocated dimension and strides arrays for the new array object.


If data is provided, it must stay alive for the life of the array. This function steals a reference to descr if it is not NULL. If subok is 1, the newly created array will use the sub-type of prototype to create the new array, otherwise it will create a base-class array. If the type always has the same number of bytes, then itemsize is ignored. Otherwise, itemsize specifies the particular size of this array. If strides are passed in they must be consistent with the dimensions, the itemsize, and the data of the array.


Create a new uninitialized array of type, typenum , whose size in each of nd dimensions is given by the integer array, dims. This function cannot be used to create a flexible-type array no itemsize given. Create an array wrapper around data pointed to by the given pointer. The array flags will have a default that the data area is well-behaved and C-style contiguous.


The shape of the array is given by the dims c-array of length nd. The data-type of the array is indicated by typenum. If data comes from another reference-counted Python object, the reference count on this object should be increased after the pointer is passed in, and the base member of the returned ndarray should point to the Python object that owns the data.


This will ensure that the provided memory is not freed while the returned array is in existence. Create a new array with the provided data-type descriptor, descr , of the shape determined by nd and dims. Fill the array pointed to by obj —which must be a subclass of ndarray—with the contents of val evaluated as a byte. This macro calls memset, so obj must be contiguous. Construct a new nd -dimensional array with shape given by dims and data type given by dtype. If fortran is non-zero, then a Fortran-order array is created, otherwise a C-order array is created.


Construct a new 1-dimensional array of data-type, typenum , that ranges from start to stop exclusive in increments of step.


Equivalent to arange start , stop , step , dtype. Construct a new 1-dimensional array of data-type determined by descr , that ranges from start to stop exclusive in increments of step. Equivalent to arange start , stop , step , typenum. This function steals a reference to obj and sets it as the base property of arr.


If the object provided is an array, this function traverses the chain of base pointers so that each array points to the owner of the memory directly. Once the base is set, it may not be changed to another value. This is the main function used to obtain an array from any nested sequence, or object that exposes the array interface, op.


The dtype argument may be NULL , indicating that any data-type and byteorder is acceptable. A value of 0 for either of the depth parameters causes the parameter to be ignored. Any of the following array flags can be added e. If your code can handle general e. Also, if op is not already an array or does not expose the array interface , then a new array will be created and filled from op using the sequence protocol.


The context argument is unused. Make sure the returned array is aligned on proper boundaries for its data type. An aligned array has the data pointer and every strides factor as a multiple of the alignment factor for the data-type- descriptor.


Make sure a copy is made of op. If this flag is not present, data is not copied if it can be avoided. Make sure the result is a base-class ndarray. By default, if op is an instance of a subclass of ndarray, an instance of that same subclass is returned. If this flag is set, an ndarray object will be returned instead. Force a cast to the output type even if it cannot be done safely. Without this flag, a data cast will occur only if it can be done safely, otherwise an error is raised.


If op is already an array, but does not satisfy the requirements, then a copy is made which will satisfy the requirements. If op is not writeable to begin with, or if it is not already an array, then an error is raised.


Unless NumPy is made aware of an issue with this, this function is scheduled for rapid removal without replacement. In versions 1. That form of the constant names is deprecated in 1. Make sure the returned array has a data-type descriptor that is in machine byte-order, over-riding any specification in the dtype argument.


Normally, the byte-order requirement is determined by the dtype argument. If this flag is set and the dtype argument does not indicate a machine byte-order descriptor or is NULL and the object is already an array with a data-type descriptor that is not in machine byte- order , then a new data-type descriptor is created and used with its byte-order field set to native.


This function returns a well-behaved C-style contiguous array from any nested sequence or array-interface exporting object. Return an aligned and in native-byteorder array from any nested sequence or array-interface exporting object, op, of a type given by the enumerated typenum. This function steals a reference to op and makes sure that op is a base-class ndarray. Construct a one-dimensional ndarray of a single type from a binary or ASCII text string of length slen.


The data-type of the array to-be-created is given by dtype. If num is -1, then copy the entire string and return an appropriately sized array, otherwise, num is the number of items to copy from the string. Some data-types may not be readable in text mode and an error will be raised if that occurs. All errors return NULL. Construct a one-dimensional ndarray of a single type from a binary or text file.


The open file pointer is fp , the data-type of the array to be created is given by dtype. This must match the data in the file. If num is -1, then read until the end of the file and return an appropriately sized array, otherwise, num is the number of items to read. Some array types cannot be read in text mode in which case an error is raised. A writeable buffer will be tried first followed by a read- only buffer.


The data is assumed to start at offset bytes from the start of the memory location for the object. The type of the data in the buffer will be interpreted depending on the data- type descriptor, dtype.


If count is negative then it will be determined from the size of the buffer and the requested itemsize, otherwise, count represents how many elements should be converted from the buffer.


Copy from the source array, src , into the destination array, dest , performing a data-type conversion if necessary. If an error occurs return -1 otherwise 0.


The shape of src must be broadcastable to the shape of dest. The data areas of dest and src must not overlap. Assign an object src to a NumPy array dest according to array-coercion rules. Returns 0 on success and -1 on failures. Move data from the source array, src , into the destination array, dest , performing a data-type conversion if necessary.


The data areas of dest and src may overlap. If op is already C-style contiguous and well-behaved then just return a reference, otherwise return a contiguous and well-behaved copy of the array. The parameter op must be a sub-class of an ndarray and no checking for that is done. Convert obj to an ndarray. The argument can be any nested sequence or object that exports the array interface. Your code must be able to handle any data-type descriptor and any combination of data-flags to use this macro.


Standard combinations of flags can also be used:. The output is a converted version of the input so that requirements are met and if needed a flattening has occurred. If op implements any part of the array interface, then out will contain a new reference to the newly created ndarray using the interface or out will contain NULL if an error during conversion occurs. Evaluates true if op is an instance of a builtin numeric type int, float, complex, long, bool.


Evaluates true if op is a builtin Python scalar object int, float, complex, bytes, str, long, bool. For the typenum macros, the argument is an integer representing an enumerated array data type. Type represents an enumerated type corresponding to one of the standard Python scalar bool, int, float, or complex. Type has no size information attached, and can be resized. Should only be called on flexible dtypes. Types that are attached to an array will always be sized, hence the array form of this macro not existing.


Return a new array object with the elements of arr cast to the data-type typenum which must be one of the enumerated types and not a flexible type. Return a new array of the type specified, casting the elements of arr as appropriate.


The fortran argument specifies the ordering of the output array. As of 1. Cast the elements of the array in into the array out. The output array should be writeable, have an integer-multiple of the number of elements in the input array more than one copy can be placed in out , and have a data type that is one of the builtin types. Returns 0 on success and -1 if an error occurs. Return the low-level casting function to cast from the given descriptor to the builtin type number. If no casting function exists return NULL and set an error.


Returns non-zero if an array of data type fromtype can be cast to an array of data type totype without losing information. An exception is that bit integers are allowed to be cast to bit floating point values even though this can lose precision on large integers so as not to proliferate the use of long doubles without explicit requests.


Flexible array types are not checked according to their lengths with this function. Returns non-zero if an array of data type fromtype which can include flexible types can be cast safely to an array of data type totype which can include flexible types according to the casting rule casting.


Returns non-zero if arr can be cast to totype according to the casting rule given in casting. If arr is an array scalar, its value is taken into account, and non-zero is also returned when the value will not overflow or be truncated to an integer when converting to a smaller type.


If arr is an array, returns its data type descriptor, but if arr is an array scalar has 0 dimensions , it finds the data type of smallest size to which the value may be converted without overflow or truncation to an integer.


This function will not demote complex to float or anything to boolean, but will demote a signed integer to an unsigned integer when the scalar value is positive. Finds the data type of smallest size and kind to which type1 and type2 may be safely converted.


This function is symmetric and associative. A string or unicode result will be the proper size for storing the max value of the input types converted to a string or unicode. This applies type promotion to all the inputs, using the NumPy rules for combining scalars and arrays, to determine the output type of a set of operands.


This is the same result type that ufuncs produce. The specific algorithm used is as follows. This function is useful for determining a common type that two or more arrays can be converted to.