在pycharm进行debug的时候报错NameError: name 'find' is not defined,网上查找了一下,说是要写成str.find()的形式,但尝试改了几次都没有成功,。程序如下
from typing import Union, Any, Optional
from kaczmarzReg import *
from pseudoinverse import *
from pylab import *
import h5py
import urllib
import os
import urllib.request
# Download measurement and systemMatrix from http://media.tuhh.de/ibi/mdf/
filenameSM = "systemMatrix.mdf"
filenameMeas = "measurement.mdf"
if not os.path.isfile(filenameSM):
fileSM = urllib.request.FancyURLopener()
fileSM.retrieve('http://media.tuhh.de/ibi/mdfv2/systemMatrix_V2.mdf', filenameSM)
if not os.path.isfile(filenameMeas):
fileMeas = urllib.request.FancyURLopener()
fileMeas.retrieve('http://media.tuhh.de/ibi/mdfv2/measurement_V2.mdf', filenameMeas)
fSM = h5py.File(filenameSM, 'r')
fMeas = h5py.File(filenameMeas, 'r')
# read the full system matrix
S = fSM['/measurement/data']
# reinterpret to complex data
S = S[:,:,:,:].squeeze()
# get rid of background frames
isBG = fSM['/measurement/isBackgroundFrame'][:].view(bool)
print(S.shape)
S = S[:,:,isBG == False]
# read the measurement data
u = fMeas['/measurement/data']
u = u[:,:,:,:].squeeze()
u = rfft(u)
# generate frequency vector
numFreq = round(fMeas['/acquisition/receiver/numSamplingPoints'].value/2)+1
rxBandwidth = fMeas['/acquisition/receiver/bandwidth'].value
freq = arange(0,numFreq)/(numFreq-1)*rxBandwidth
# remove frequencies below 80 kHz and use only x/y receive channels 移除低于 80 kHz 的频率并仅使用 x/y 接收通道
idxMin = find(freq[:] > 80e3)[0]
S = S[0:2,idxMin:-1,:]
u = u[:,0:2,idxMin:-1]
print(shape(S))
print(shape(u))
# merge frequency and receive channel dimensions
S = reshape(S, (shape(S)[0]*shape(S)[1],shape(S)[2]))
u = reshape(u, (shape(u)[0],shape(u)[1]*shape(u)[2]))
# average over all temporal frames
u = mean(u,axis=0)
# reconstruct
c = kaczmarzReg(S,u,3,norm(S,ord='fro')*1e-3,False,True,True)
# reconstruct using signular value decomposition
U, Sigm, V = svd(S, full_matrices=False)
csvd = pseudoinverse(U, Sigm, V, u, 5e2, True, True)
# reshape into an image
N = fSM['/calibration/size'][:]
c = reshape(c,(N[0],N[1]))
csvd = reshape(csvd,(N[0],N[1]))
# plot kaczmarz reconstruction
figure()
gray()
imshow(real(transpose(c)), interpolation="None")
# plot pseudoinverse reconstruction
figure()
gray()
imshow(real(transpose(csvd)), interpolation="None")
show()
不知道该如何改正,请求帮助。
python自带的find函数是操作字符串的,我看你这个不像是要用自带的find函数,那么问题就来了,你是自定义的还是导入的库里的函数,你得给个出处啊,要不从库里指定导入,要不你自己写个find函数
find未被定义,不知道你这个find是个什么,要做什么样的操作,
如果是要做检索的话是
str.find(str, beg=0, end=len(string))
参数
str -- 指定检索的字符串
beg -- 开始索引,默认为0。
end -- 结束索引,默认为字符串的长度。
你用错了,比如说这句,你要处理的数据为str
idxMin = str.find(freq[:] > 80e3)[0]
应该这样写