导航:首页 > 编程语言 > 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相关的资料

热点内容
pythonclass使用方法 浏览:221
移动加密软件去哪下载 浏览:281
php弹出alert 浏览:207
吉林文档课件加密费用 浏览:131
传感器pdf下载 浏览:284
随车拍app绑定什么设备 浏览:896
方维团购系统源码 浏览:991
linux反弹shell 浏览:158
打印机接口加密狗还能用吗 浏览:299
二板股票源码 浏览:448
度人经pdf 浏览:902
怎么配置android远程服务器地址 浏览:960
java程序员看哪些书 浏览:943
什么app可以免费和外国人聊天 浏览:797
pdf手写笔 浏览:182
别永远伤在童年pdf 浏览:990
爱上北斗星男友在哪个app上看 浏览:421
主力散户派发源码 浏览:671
linux如何修复服务器时间 浏览:61
荣县优途网约车app叫什么 浏览:479