def find_def(defs, module_name): """Find occurences of a function in a module. np.lookfor(what, module=None, import_modules=True, regenerate=False, output=None): Parameters ---------- defs : text singleton or list The name of a def or a list of them. These are what is being searched. module_name : name, no quotes The name of the module that was imported. """ if not isinstance(defs, (list, tuple)): defs = [defs] for i in defs: print("\n{}\n{}".format("=" * 20, i)) np.lookfor(i, module_name)
def lookfor(what): """Do a keyword search on scikit-image docstrings. Parameters ---------- what : str Words to look for. """ import numpy as np import sys return np.lookfor(what, sys.modules[__name__])
def lookfor(what): """Do a keyword search on scikit-image docstrings. Parameters ---------- what : str Words to look for. Examples -------- >>> import skimage >>> skimage.lookfor('regular_grid') Search results for 'regular_grid' --------------------------------- skimage.lookfor Do a keyword search on scikit-image docstrings. skimage.util.regular_grid Find `n_points` regularly spaced along `ar_shape`. """ return np.lookfor(what, sys.modules[__name__.split('.')[0]])
def lookfor(what): """Do a keyword search on scikit-image docstrings. Parameters ---------- what : str Words to look for. Examples -------- >>> import skimage >>> skimage.lookfor('regular_grid') # doctest: +SKIP Search results for 'regular_grid' --------------------------------- skimage.lookfor Do a keyword search on scikit-image docstrings. skimage.util.regular_grid Find `n_points` regularly spaced along `ar_shape`. """ return np.lookfor(what, sys.modules[__name__.split('.')[0]])
from __future__ import annotations from io import StringIO from typing import Any import numpy as np FILE = StringIO() AR: np.ndarray[Any, np.dtype[np.float64]] = np.arange(10).astype(np.float64) def func(a: int) -> bool: ... np.deprecate(func) np.deprecate() np.deprecate_with_doc("test") np.deprecate_with_doc(None) np.byte_bounds(AR) np.byte_bounds(np.float64()) np.info(1, output=FILE) np.source(np.interp, output=FILE) np.lookfor("binary representation", output=FILE)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sat Jan 14 14:04:16 2017 @author: attilakiss """ import numpy as np a = np.ones((3, 3)) print(a) np.lookfor('delete array') np.array? x=np.array(np.mat('1 2 3; 3 4 5; 4 4 3 ')) y=(x+1) np.con*? np.delete? arr = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]]) print(arr) c=np.delete(arr, 2, 1) print(c) print(arr," \n",c, arr.ndim, arr.shape, c.ndim, c.shape) s=np.array(range(100)) print(s) print(s[20:])
def search(what): """Utility function to search docstrings for string `what`.""" np.lookfor(what, module="pygimli", import_modules=False)
# convert an array to a different type print("Convert the array into different type: ", my_array.astype(int)) # TRANSPOSING ARRAY # Transpose `x` print("Array using transpose : \n", np.transpose(x)) # Or use `T` to transpose `my_2d_array` print("Array using .T option to transpose :\n ", x.T) # Use lookfor() to do a keyword search on docstrings. # Look up info on `mean` with `np.lookfor()` print(np.lookfor("mean")) # Get info on data types with `np.info()` print(np.info(np.x.dtype)) # Initialize your array my_3d_array = np.array( [[[1, 2, 3, 4], [5, 6, 7, 8]], [[1, 2, 3, 4], [9, 10, 11, 12]]], dtype=np.int64) # Pass the array to `np.histogram()` # histogram computes the occurrences of the array that fall within each # bin which determines the area that each bar of your histogram takes up print(np.histogram(my_3d_array)) # Specify the number of bins
integralSegunda = np.polyint(f3grau, 2) integralTerceira = np.polyint(f3grau, 3) #Tratamento de sinais - convolucao #%% sinalConvoluido = np.convolve([1, 2, 3], [0, 1, 0.5]) plt.hist(sinalConvoluido, bins=3, density=100) #altere os bins plt.show() #Pesquisa print(np.info(np.polyval)) print(np.lookfor('binary representation')) print(np.source(np.interp))#funcao Valida apenas para objetos escritos em python '''Scipy É uma biblioteca de computação científica, que junto ao Numpy é capaz de realizar operações poderosas, tanto para o processamento de dados quanto para a prototipagem de sistemas.''' #%% import scipy as sp grafo = [[0,1,2,0],[0,0,0,1],[0,0,0,3],[0,0,0,0]]
# coding: utf-8 # In[1]: import numpy as np # In[2]: np.__version__ # Q1. Search for docstrings of the numpy functions on linear algebra. # In[4]: np.lookfor('linear algebra') # Q2. Get help information for numpy dot function. # In[9]: np.info(np.dot)
from io import StringIO from typing import Any, Dict import numpy as np AR: np.ndarray[Any, np.dtype[np.float64]] AR_DICT: Dict[str, np.ndarray[Any, np.dtype[np.float64]]] FILE: StringIO def func(a: int) -> bool: ... reveal_type(np.deprecate(func)) # E: def (a: builtins.int) -> builtins.bool reveal_type(np.deprecate()) # E: _Deprecate reveal_type(np.deprecate_with_doc("test")) # E: _Deprecate reveal_type(np.deprecate_with_doc(None)) # E: _Deprecate reveal_type(np.byte_bounds(AR)) # E: Tuple[builtins.int, builtins.int] reveal_type(np.byte_bounds(np.float64())) # E: Tuple[builtins.int, builtins.int] reveal_type(np.who(None)) # E: None reveal_type(np.who(AR_DICT)) # E: None reveal_type(np.info(1, output=FILE)) # E: None reveal_type(np.source(np.interp, output=FILE)) # E: None reveal_type(np.lookfor("binary representation", output=FILE)) # E: None reveal_type(np.safe_eval("1 + 1")) # E: Any
import numpy as np np.deprecate(1) # E: No overload variant np.deprecate_with_doc(1) # E: incompatible type np.byte_bounds(1) # E: incompatible type np.who(1) # E: incompatible type np.lookfor(None) # E: incompatible type np.safe_eval(None) # E: incompatible type
import matplotlib.pyplot as plt a = np.array(range(5)) # Compare to timing of python data structures L = list(range(1000)) %timeit [i**2 for i in L] # 449 µs ± 193 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each) a = np.arange(1000) %timeit a**2 # 4.02 µs ± 41.1 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) # Two orders of magnitude speed increase! # Use np.lookfor() to look for numpy functions np.lookfor('mean') np.mean(a) # Use wildcard with ? to look for function names np.me*? # Making arrays a = np.array(range(4)) a.ndim a.shape len(a) b = np.array([range(3), range(3)]) b.ndim b.shape len(b)
from tools import addNoises from translationTest import * import numpy as np np.lookfor('matlib') image, vector = initialImage() result = addNoises(image) print(np.mat(np.reshape(result[0], (10, 10))))
import numpy as np np.lookfor('binary representation')
# http://www.scipy-lectures.org/intro/numpy/numpy.html import numpy as np r = np.lookfor('create array') # l = globals().copy() # for v in l: # print ("'" + v + "'" + ": instance_of_class_name(\"" + type(l[v]).__name__ + "\"),")