導航:首頁 > 編程語言 > pythonnumpyfind

pythonnumpyfind

發布時間:2022-08-16 09:55:04

python 矩陣操作, 篩選符合條件的行

我舉個簡單的例子:


取出含有元素0的所有行

importnumpyasnp
x=np.array([[1,2,3,4,0],[2,3,4,5,6],[0,1,2,3,4]])
b=[]
forrowinx:
foriinrow:
ifi==0:
b.append(row)
printb

PS G:Python learning-Q> python ex.py

[array([1, 2, 3, 4, 0]), array([0, 1, 2, 3, 4])]

Ⅱ 怎麼查找python列表中元素的位置

Python中查找list中某個固定元素是常有的事,對於兩種不同的查找有兩種不同的解決方案,見下。

查找元素首次出現的位置:

(2)pythonnumpyfind擴展閱讀:

序列是Python中最基本的數據結構。序列中的每個元素都分配一個數字 - 它的位置,或索引,第一個索引是0,第二個索引是1,依此類推。

Python有6個序列的內置類型,但最常見的是列表和元組。序列都可以進行的操作包括索引,切片,加,乘,檢查成員。

此外,Python已經內置確定序列的長度以及確定最大和最小的元素的方法。列表是最常用的Python數據類型,它可以作為一個方括弧內的逗號分隔值出現。列表的數據項不需要具有相同的類型。

Ⅲ 利用python進行數據分析中第六章 findall什麼意思

python進行數據分析主要是numpy、matplotlib這兩個模塊包,進階之後,符號運算用scipy,機器學慣用scikit-learn,時間序列用pandas,numpy和matplotlib一定要熟練

Ⅳ 如何計算百分位數與Python / numpy的

1. 你可能會喜歡SciPy的統計軟體包。它有百分函數你之後,許多其他統計好吃的東西。
此票證相信他們不會被整合percentile()到numpy的很快。
2.
順便說一句,有百分函數的純Python,萬一一個不希望依賴於SciPy的。具體函數如下復制:
## {{{ CodeGo.net (r1)
import math
import functools
def percentile(N, percent, key=lambda x:x):
"""
Find the percentile of a list of values.
@parameter N - is a list of values. Note N MUST BE already sorted.
@parameter percent - a float value from 0.0 to 1.0.
@parameter key - optional key function to compute value from each element of N.
@return - the percentile of the values
"""
if not N:
return None
k = (len(N)-1) * percent
f = math.floor(k)
c = math.ceil(k)
if f == c:
return key(N[int(k)])
d0 = key(N[int(f)]) * (c-k)
d1 = key(N[int(c)]) * (k-f)
return d0+d1
# median is 50th percentile.
median = functools.partial(percentile, percent=0.5)
## end of CodeGo.net }}}

3.
檢查scipy.stats模塊:
scipy.stats.scoreatpercentile
4.
import numpy as np
a = [154, 400, 1124, 82, 94, 108]
print np.percentile(a,95) # gives the 95th percentile

5.
百分看到定義預期結果從提供的列表,低於該值的百分之P被發現的價值。為了得到這一點,你一個簡單的函數。
def percentile(N, P):
"""
Find the percentile of a list of values
@parameter N - A list of values. N must be sorted.
@parameter P - A float value from 0.0 to 1.0
@return - The percentile of the values.
"""
n = int(round(P * len(N) + 0.5))
return N[n-1]
# A = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
# B = (15, 20, 35, 40, 50)
#
# print percentile(A, P=0.3)
# 4
# print percentile(A, P=0.8)
# 9
# print percentile(B, P=0.3)
# 20
# print percentile(B, P=0.8)
# 50

如果您寧願從處於或低於該值的百分之P被發現所提供的列表中獲得的價值,這個簡單的修改:
def percentile(N, P):
n = int(round(P * len(N) + 0.5))
if n > 1:
return N[n-2]
else:
return 0

6.
numpy.percentile
在那裡我很想念?
7.
size=len(mylist)
p5=mylist[math.ceil((size*5)/100)-1]
p25=mylist[math.ceil((size*25)/100)-1]
p50=mylist[math.ceil((size*50)/100)-1]
p75=mylist[math.ceil((size*75)/100)-1]
p95=mylist[math.ceil((size*95)/100)-1]

Ⅳ python3.5中,無法numpy怎麼解決

1、可以用python自帶的安裝工具,pip install numpy scipy 等。

2、如果沒有pip的話,可以試試easy-install numpy scipy。打開cmd,在裡面輸入這些命令

Ⅵ 如何用python取圖片輪廓

1、查找輪廓(find_contours)

measure模塊中的find_contours()函數,可用來檢測二值圖像的邊緣輪廓。

函數原型為:

skimage.measure.find_contours(array,level)

array: 一個二值數組圖像

level: 在圖像中查找輪廓的級別值

返回輪廓列表集合,可用for循環取出每一條輪廓。

例1:

importnumpyasnp
importmatplotlib.pyplotasplt
fromskimageimportmeasure,draw

#生成二值測試圖像
img=np.zeros([100,100])
img[20:40,60:80]=1#矩形
rr,cc=draw.circle(60,60,10)#小圓
rr1,cc1=draw.circle(20,30,15)#大圓
img[rr,cc]=1
img[rr1,cc1]=1

#檢測所有圖形的輪廓
contours=measure.find_contours(img,0.5)

#繪制輪廓
fig,(ax0,ax1)=plt.subplots(1,2,figsize=(8,8))
ax0.imshow(img,plt.cm.gray)
ax1.imshow(img,plt.cm.gray)
forn,contourinenumerate(contours):
ax1.plot(contour[:,1],contour[:,0],linewidth=2)
ax1.axis('image')
ax1.set_xticks([])
ax1.set_yticks([])
plt.show()

結果如下:不同的輪廓用不同的顏色顯示

Ⅶ python簡單問題

用到的知識是python的string 類的一個方法,find()和index().

另外,第一行看起來少了一個 「=」。

學習python比其他語言更容易的原因就是寫代碼和測試很容易,這也是所有腳本語言的優勢。

Ⅷ py2exe python24 NumPy錯誤意思是問題,怎麼解決

from distutils.core import setup
import py2exe

from distutils.filelist import findall
import os
import matplotlib
matplotlibdatadir = matplotlib.get_data_path()
matplotlibdata = findall(matplotlibdatadir)
matplotlibdata_files = []
for f in matplotlibdata:
dirname = os.path.join('matplotlibdata', f[len(matplotlibdatadir)+1:])
matplotlibdata_files.append((os.path.split(dirname)[0], [f]))

packages = ['matplotlib', 'pytz']
includes = []
excludes = []
dll_excludes = ['libgdk_pixbuf-2.0-0.dll',
'libgobject-2.0-0.dll',
'libgdk-win32-2.0-0.dll',
'wxmsw26uh_vc.dll']

opts = { 'py2exe': { 'packages' : packages,
'includes' : includes,
'excludes' : excludes,
'dll_excludes' : dll_excludes
}
}

setup ( console=['test.py'],
options = opts,
data_files = matplotlibdata_files
)

I compile the application by running >setup.py py2exe
At the end of compilation phase, it is written :
The following moles appear to be missing

['AppKit', 'FFT', 'Foundation', 'Image', 'LinearAlgebra', 'MA', 'MLab', 'Matrix', 'Numeric', 'PyObjCTools', 'P
yQt4', 'Pyrex', 'Pyrex.Compiler', 'RandomArray', '_curses', '_ssl', 'backends.draw_if_interactive', 'backends.
new_figure_manager', 'backends.pylab_setup', 'backends.show', 'cairo', 'cairo.gtk', 'fcompiler.FCompiler', 'fc
ompiler.show_fcompilers', 'fltk', 'gd', 'gobject', 'gtk', 'lib.add_newdoc', 'matplotlib.enthought.pyface.actio
n', 'mlab.amax', 'mlab.amin', 'numarray', 'numarray.convolve', 'numarray.fft', 'numarray.ieeespecial', 'numarr
ay.linear_algebra', 'numarray.linear_algebra.mlab', 'numarray.ma', 'numarray.numeric', 'numarray.random_array'
, 'numerix.ArrayType', 'numerix.Complex', 'numerix.Complex32', 'numerix.Complex64', 'numerix.Float', 'numerix.
Float32', 'numerix.Float64', 'numerix.Int', 'numerix.Int16', 'numerix.Int32', 'numerix.Int8', 'numerix.NewAxis
', 'numerix.UInt16', 'numerix.UInt32', 'numerix.UInt8', 'numerix.absolute', 'numerix.add', 'numerix.all', 'num
erix.allclose', 'numerix.alltrue', 'numerix.arange', 'numerix.arccos', 'numerix.arccosh', 'numerix.arcsin', 'n
umerix.arcsinh', 'numerix.arctan', 'numerix.arctan2', 'numerix.arctanh', 'numerix.argmax', 'numerix.argmin', '
numerix.argsort', 'numerix.around', 'numerix.array', 'numerix.arrayrange', 'numerix.asarray', 'numerix.asum',
'numerix.bitwise_and', 'numerix.bitwise_or', 'numerix.bitwise_xor', 'numerix.ceil', 'numerix.choose', 'numerix
.clip', 'numerix.compress', 'numerix.concatenate', 'numerix.conjugate', 'numerix.convolve', 'numerix.cos', 'nu
merix.cosh', 'numerix.cross_correlate', 'numerix.cumproct', 'numerix.cumsum', 'numerix.diagonal', 'numerix.d
ivide', 'numerix.dot', 'numerix.equal', 'numerix.exp', 'numerix.fabs', 'numerix.fft.fft', 'numerix.fft.inverse
_fft', 'numerix.floor', 'numerix.fmod', 'numerix.fromfunction', 'numerix.fromstring', 'numerix.greater', 'nume
rix.greater_equal', 'numerix.hypot', 'numerix.identity', 'numerix.indices', 'numerix.innerproct', 'numerix.i
scontiguous', 'numerix.less', 'numerix.less_equal', 'numerix.log', 'numerix.log10', 'numerix.logical_and', 'nu
merix.logical_not', 'numerix.logical_or', 'numerix.logical_xor', 'numerix.matrixmultiply', 'numerix.maximum',
'numerix.minimum', 'numerix.mlab.amax', 'numerix.mlab.amin', 'numerix.mlab.cov', 'numerix.mlab.diff', 'numerix
.mlab.hanning', 'numerix.mlab.rand', 'numerix.mlab.std', 'numerix.mlab.svd', 'numerix.multiply', 'numerix.nega
tive', 'numerix.newaxis', 'numerix.nonzero', 'numerix.not_equal', 'numerix.nx', 'numerix.ones', 'numerix.outer
proct', 'numerix.pi', 'numerix.power', 'numerix.proct', 'numerix.put', 'numerix.putmask', 'numerix.rank',
'numerix.ravel', 'numerix.repeat', 'numerix.reshape', 'numerix.resize', 'numerix.searchsorted', 'numerix.shape
', 'numerix.sin', 'numerix.sinh', 'numerix.size', 'numerix.sometrue', 'numerix.sort', 'numerix.sqrt', 'numerix
.subtract', 'numerix.swapaxes', 'numerix.take', 'numerix.tan', 'numerix.tanh', 'numerix.trace', 'numerix.trans
pose', 'numerix.typecode', 'numerix.typecodes', 'numerix.where', 'numerix.which', 'numerix.zeros', 'numpy.Comp
lex', 'numpy.Complex32', 'numpy.Complex64', 'numpy.Float', 'numpy.Float32', 'numpy.Float64', 'numpy.Infinity',
'numpy.Int', 'numpy.Int16', 'numpy.Int32', 'numpy.Int8', 'numpy.UInt16', 'numpy.UInt32', 'numpy.UInt8', 'nump
y.inf', 'numpy.infty', 'numpy.oldnumeric', 'objc', 'paint', 'pango', 'pre', 'pyemf', 'qt', 'setuptools', 'setu
ptools.command', 'setuptools.command.egg_info', 'trait_sheet', 'matplotlib.numerix.Float', 'matplotlib.numerix
.Float32', 'matplotlib.numerix.absolute', 'matplotlib.numerix.alltrue', 'matplotlib.numerix.asarray', 'matplot
lib.numerix.ceil', 'matplotlib.numerix.equal', 'matplotlib.numerix.fromstring', 'matplotlib.numerix.indices',
'matplotlib.numerix.put', 'matplotlib.numerix.ravel', 'matplotlib.numerix.sqrt', 'matplotlib.numerix.take', 'm
atplotlib.numerix.transpose', 'matplotlib.numerix.where', 'numpy.core.conjugate', 'numpy.core.equal', 'numpy.c
ore.less', 'numpy.core.less_equal', 'numpy.dft.old', 'numpy.random.rand', 'numpy.random.randn']

1) First Problem: numpy\core\_internal.pyc not included in Library.zip
No scipy-style subpackage 'core' found in C:\WinCE\Traces\py2exe test\dist\library.zip\numpy. Ignoring: No mole named _internal
Traceback (most recent call last):
File "profiler_ftt.py", line 15, in ?
from matplotlib.backends.backend_wx import Toolbar, FigureCanvasWx,\
File "matplotlib\backends\backend_wx.pyc", line 152, in ?
File "matplotlib\backend_bases.pyc", line 10, in ?
File "matplotlib\colors.pyc", line 33, in ?
File "matplotlib\numerix\__init__.pyc", line 67, in ?
File "numpy\__init__.pyc", line 35, in ?
File "numpy\_import_tools.pyc", line 173, in __call__
File "numpy\_import_tools.pyc", line 68, in _init_info_moles
File "<string>", line 1, in ?
File "numpy\lib\__init__.pyc", line 5, in ?
File "numpy\lib\type_check.pyc", line 8, in ?
File "numpy\core\__init__.pyc", line 6, in ?
File "numpy\core\umath.pyc", line 12, in ?
File "numpy\core\umath.pyc", line 10, in __load
AttributeError: 'mole' object has no attribute '_ARRAY_API'

I resolved that issue by adding the file ...\Python24\Lib\site-packages\numpy\core\_internal.pyc in ...\test\dist\library.zip\numpy\core.
Each time I compile that executable, I add the file by hand.
Does anybody know how to automatically add that file?
2) Second problem: I don't know how to resolve that issue:
Traceback (most recent call last):
File "profiler_ftt.py", line 15, in ?
from matplotlib.backends.backend_wx import Toolbar, FigureCanvasWx,\
File "matplotlib\backends\backend_wx.pyc", line 152, in ?
File "matplotlib\backend_bases.pyc", line 10, in ?
File "matplotlib\colors.pyc", line 33, in ?
File "matplotlib\numerix\__init__.pyc", line 67, in ?
File "numpy\__init__.pyc", line 35, in ?
File "numpy\_import_tools.pyc", line 173, in __call__
File "numpy\_import_tools.pyc", line 68, in _init_info_moles
File "<string>", line 1, in ?
File "numpy\random\__init__.pyc", line 3, in ?
File "numpy\random\mtrand.pyc", line 12, in ?
File "numpy\random\mtrand.pyc", line 10, in __load
File "numpy.pxi", line 32, in mtrand
AttributeError: 'mole' object has no attribute 'dtype'

I don't find the file numpy.pxi in my file tree nor in \test\dist\library.zip.
I browsed the web in the hope to find a solution but nothing.
It seems that this issue is well known but no solution provided in mailing lists.

Ⅸ python: numpy的ndarray和array有什麼區別為什麼不能plt.imshow()一個ndarray矩陣

問:What is the difference between ndarray and array in Numpy? And where can I find the implementations in the numpy source code?
(Numpy中ndarray和array的區別是什麼?我在哪兒能夠找到numpy中相應的實現?)
答:Well, np.array is just a convenience function to create an ndarray, it is not a class itself.
(嗯,np.array只是一個便捷的函數,用來創建一個ndarray,它本身不是一個類)
You can also create an array using np.ndarray, but it is not the recommended way. From the docstring of np.ndarray:
(你也能夠用np.ndarray來創建,但這不是推薦的方式。來自np.ndarray的文檔:)
Arrays should be constructed using array, zeros or empty … The parameters given here refer to a low-level method (ndarray(…)) for instantiating an array.
(Arrays 應該能用array,zeros 或empty來構造…這里的參數和一個實例化array的低層方法與有關)

Ⅹ python中有沒有同matlab中find函數功能相同的指令

有的,我正好也在做類似的程序。
PYTHON中引入NUMPY的第三方庫,矩陣可以用ndarray類型代替,ndarray是numpy的默認類型。
ndarray這個類型的對象,有where函數可以用。你可以搜索一下這個函數的用法

閱讀全文

與pythonnumpyfind相關的資料

熱點內容
解壓新奇特視頻 瀏覽:702
圖書信息管理系統java 瀏覽:548
各種直線命令詳解 瀏覽:859
程序員淚奔 瀏覽:143
素材怎麼上傳到伺服器 瀏覽:513
android百度離線地圖開發 瀏覽:187
web可視化編程軟體 瀏覽:288
java筆試編程題 瀏覽:742
win11什麼時候可以裝安卓 瀏覽:560
java不寫this 瀏覽:999
雲點播電影網php源碼 瀏覽:95
pythonclass使用方法 瀏覽:226
移動加密軟體去哪下載 瀏覽:294
php彈出alert 瀏覽:209
吉林文檔課件加密費用 瀏覽:136
感測器pdf下載 瀏覽:289
隨車拍app綁定什麼設備 瀏覽:898
方維團購系統源碼 瀏覽:993
linux反彈shell 瀏覽:159
列印機介面加密狗還能用嗎 瀏覽:301