https://github.com/hansalemaos/cythonflatiter

Locates values in NumPy Arrays with Cython

https://github.com/hansalemaos/cythonflatiter

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (7.6%) to scientific vocabulary

Keywords

cython isin iter numpy
Last synced: 5 months ago · JSON representation

Repository

Locates values in NumPy Arrays with Cython

Basic Info
Statistics
  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
cython isin iter numpy
Created about 2 years ago · Last pushed about 2 years ago
Metadata Files
Readme License

README.MD

Locates values in NumPy Arrays with Cython

pip install cythonflatiter

Tested against Windows / Python 3.11 / Anaconda

Cython (and a C/C++ compiler) must be installed

FlatIterArray is a utility class for efficiently searching multi-dimensional array data.

```python | init(self, a, dtype=, unordered=True) | Initializes a FlatIterArray instance. |
| Parameters: | - a (numpy.ndarray): The input array. | - dtype (numpy.dtype, optional): The data type of the index array that will be created. Defaults to np.int64. (It's better not to change that, because it corresponds to cython.Pyssizet) | - unordered (bool, optional): Flag indicating whether to use unordered iterations. Defaults to True. (index array will be created using multiprocessing) |
| getflatpointerarrayfromorigdata(self) | Returns a flat pointer array from the original data. | If you change data here, it changes also in the original array |
| Returns: | - numpy.ndarray: Flat pointer array. |
| searchmultiplevaluesinarray(self, values) | Searches for multiple values in the array and returns indices and values. |
| Parameters: | - values (list or numpy.ndarray): List of values to search for. |
| Returns: | - tuple: Array of indices and array of found values. |
| searchsinglevalueinarray(self, value) | Searches for a single value in the array and returns indices. |
| Parameters: | - value: The value to search for. |
| Returns: | - numpy.ndarray: Array of indices. |
| sequenceisindimension(self, seq, lastdim) | Checks if a sequence is in a dimension |
| Parameters: | - seq (list or numpy.ndarray): List of values representing the sequence. | - lastdim: The dimension to search in. |
| Returns: | - numpy.ndarray: Array of indices. |
| update
iterarray(self, dtype=, unordered=True) | Updates the iterray attribute with new parameters. |
| Parameters: | - dtype (numpy.dtype, optional): The data type of the index array that will be created. Defaults to np.int64. | - unordered (bool, optional): Flag indicating whether to use unordered iterations. Defaults to True. (index array will be created using multiprocessing) |
| valueisindimension(self, value, lastdim) | Checks if a value is in a dimension |
| Parameters: | - value: The value to search for. | - last_dim: The dimension to search in. |
| Returns: | - numpy.ndarray: Array of indices.

import numpy as np import cv2 from cythonflatiter import FlatIterArray

data = cv2.imread(r"C:\Users\hansc\Desktop\2023-08-29xx160730-Window.png") f = FlatIterArray(data, dtype=np.int64, unordered=True) results255inarray = f.searchsinglevalueinarray(255)

results255inarray

Out[6]:

array([[195330, 34, 0, 0],

[201075, 35, 0, 0],

[206820, 36, 0, 0],

...,

[488324, 84, 1914, 2],

[494069, 85, 1914, 2],

[499814, 86, 1914, 2]], dtype=int64)

print(data[84,1914,2])

print(data[34,0,0])

255

255

indices, foundvalues = f.searchmultiplevaluesin_array(values=[255, 11, 0])

indices,found_values

Out[12]:

(array([[195330, 34, 0, 0],

[201075, 35, 0, 0],

[206820, 36, 0, 0],

...,

[488324, 84, 1914, 2],

[494069, 85, 1914, 2],

[499814, 86, 1914, 2]], dtype=int64),

array([255, 255, 255, ..., 255, 255, 255], dtype=uint8))

concatvalues = np.hstack([indices, foundvalues.reshape((-1, 1))])

print(concat_values)

[[195330 34 0 0 255]

[201075 35 0 0 255]

[206820 36 0 0 255]

...

[488324 84 1914 2 255]

[494069 85 1914 2 255]

[499814 86 1914 2 255]]

print(data[85,1914,2])

print(data[36,0,0])

lastdimwith255 = f.valueisin_dimension(255, 3)

lastdimwith255

Out[31]:

array([[195330, 34, 0],

[201075, 35, 0],

[206820, 36, 0],

...,

[488322, 84, 1914],

[494067, 85, 1914],

[499812, 86, 1914]], dtype=int64)

print(data[86,1914])

print(data[34,0])

[255 255 255]

[255 255 255]

penultimatedimwith255255 = f.sequenceisin_dimension([255, 255, 255], 2)

penultimatedimwith255255

Out[38]:

array([[ 0, 0],

[ 5745, 1],

[ 11490, 2],

...,

[5538180, 964],

[5543925, 965],

[5549670, 966]], dtype=int64)

data[964]

Out[40]:

array([[255, 255, 255],

[255, 255, 255],

[255, 255, 255],

...,

[ 43, 43, 43],

[ 43, 43, 43],

[ 43, 43, 43]], dtype=uint8)

ultimatedimwith255255255 = f.sequenceisin_dimension([255, 255, 255], 3)

ultimatedimwith255255255

Out[42]:

array([[195330, 34, 0],

[201075, 35, 0],

[206820, 36, 0],

...,

[488322, 84, 1914],

[494067, 85, 1914],

[499812, 86, 1914]], dtype=int64)

[750 433 0]

[751 433 0]

[752 433 0]

[753 433 0]

[754 433 0]

[755 433 0]

[756 433 0]

[757 433 0]

[758 433 0]

```

Owner

  • Name: Hans Alemão
  • Login: hansalemaos
  • Kind: user
  • Location: Sao Paulo

A native German teacher living in Brazil who likes C++ accelerated Python

GitHub Events

Total
Last Year

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 14 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 1
  • Total maintainers: 1
pypi.org: cythonflatiter

Locates values in NumPy Arrays with Cython

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 14 Last month
Rankings
Dependent packages count: 10.1%
Average: 38.6%
Dependent repos count: 67.1%
Maintainers (1)
Last synced: 6 months ago