-
nx=length(x(:));
if nargin<2 || isempty(win)
win=nx;
end
if nargin<4 || isempty(m)
m='';
end
nwin=length(win);
if nwin == 1
lw = win;
w = ones(1,lw);
else
lw = nwin;
w = win(:)';
end
標簽:
能頻值
上傳時間:
2019-09-23
上傳用戶:minwenji
-
# include<stdio.h>
# include<math.h>
# define N 3
main(){
float NF2(float *x,float *y);
float A[N][N]={{10,-1,-2},{-1,10,-2},{-1,-1,5}};
float b[N]={7.2,8.3,4.2},sum=0;
float x[N]= {0,0,0},y[N]={0},x0[N]={};
int i,j,n=0;
for(i=0;i<N;i++)
{
x[i]=x0[i];
}
for(n=0;;n++){
//計算下一個值
for(i=0;i<N;i++){
sum=0;
for(j=0;j<N;j++){
if(j!=i){
sum=sum+A[i][j]*x[j];
}
}
y[i]=(1/A[i][i])*(b[i]-sum);
//sum=0;
}
//判斷誤差大小
if(NF2(x,y)>0.01){
for(i=0;i<N;i++){
x[i]=y[i];
}
}
else
break;
}
printf("經過%d次雅可比迭代解出方程組的解:\n",n+1);
for(i=0;i<N;i++){
printf("%f ",y[i]);
}
}
//求兩個向量差的二范數函數
float NF2(float *x,float *y){
int i;
float z,sum1=0;
for(i=0;i<N;i++){
sum1=sum1+pow(y[i]-x[i],2);
}
z=sqrt(sum1);
return z;
}
標簽:
C語言
編寫
迭代
上傳時間:
2019-10-13
上傳用戶:大萌萌撒
-
以后再也不用擔心寫爬蟲ip被封,不用擔心沒錢買代理ip的煩惱了
在使用python寫爬蟲時候,你會遇到所要爬取的網站有反爬取技術比如用同一個IP反復爬取同一個網頁,很可能會被封。如何有效的解決這個問題呢?我們可以使用代理ip,來設置代理ip池。
現在教大家一個可獲取大量免費有效快速的代理ip方法,我們訪問西刺免費代理ip網址
這里面提供了許多代理ip,但是我們嘗試過后會發現并不是每一個都是有效的。所以我們現在所要做的就是從里面提供的篩選出有效快速穩定的ip。
以下介紹的免費獲取代理ip池的方法:
優點:免費、數量多、有效、速度快
缺點:需要定期篩選
主要思路:
從網址上爬取ip地址并存儲
驗證ip是否能使用-(隨機訪問網址判斷響應碼)
格式化ip地址
代碼如下:
1.導入包
import requests
from lxml import etree
import time
1
2
3
2.獲取西刺免費代理ip網址上的代理ip
def get_all_proxy():
url = 'http://www.xicidaili.com/nn/1'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36',
}
response = requests.get(url, headers=headers)
html_ele = etree.HTML(response.text)
ip_eles = html_ele.xpath('//table[@id="ip_list"]/tr/td[2]/text()')
port_ele = html_ele.xpath('//table[@id="ip_list"]/tr/td[3]/text()')
proxy_list = []
for i in range(0,len(ip_eles)):
proxy_str = 'http://' + ip_eles[i] + ':' + port_ele[i]
proxy_list.append(proxy_str)
return proxy_list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
3.驗證獲取的ip
def check_all_proxy(proxy_list):
valid_proxy_list = []
for proxy in proxy_list:
url = 'http://www.baidu.com/'
proxy_dict = {
'http': proxy
}
try:
start_time = time.time()
response = requests.get(url, proxies=proxy_dict, timeout=5)
if response.status_code == 200:
end_time = time.time()
print('代理可用:' + proxy)
print('耗時:' + str(end_time - start_time))
valid_proxy_list.append(proxy)
else:
print('代理超時')
except:
print('代理不可用--------------->'+proxy)
return valid_proxy_list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
4.輸出獲取ip池
if __name__ == '__main__':
proxy_list = get_all_proxy()
valid_proxy_list = check_all_proxy(proxy_list)
print('--'*30)
print(valid_proxy_list)
1
2
3
4
5
技術能力有限歡迎提出意見,保證積極向上不斷學習
————————————————
版權聲明:本文為CSDN博主「彬小二」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/qq_39884947/article/details/86609930
標簽:
python
ip
代理
防止
上傳時間:
2019-11-15
上傳用戶:fygwz1982
-
function [R,k,b] = msc(A)
% 多元散射校正
% 輸入待處理矩陣,通過多元散射校正,求得校正后的矩陣
%% 獲得矩陣行列數
[m,n] = size(A);
%% 求平均光譜
M = mean(A,2);
%% 利用最小二乘法求每一列的斜率k和截距b
for i = 1:n
a = polyfit(M,A(:,i),1);
if i == 1
k = a(1);
b = a(2);
else
k = [k,a(1)];
b = [b,a(2)];
end
end
%% 求得結果
for i = 1:n
Ai = (A(:,i)-b(i))/k(i);
if i == 1
R = Ai;
else
R = [R,Ai];
end
end
標簽:
MSC
多元
散射
校正
上傳時間:
2020-03-12
上傳用戶:15275387185
-
W
?????????abooklikethistogether,manypeoplewhoneverhope
to see their namesinprint get involved and provide alot of help. I
wouldliketogivecreditwherecreditisdueandacknowledgethose
people here.
Firstandforemost,atleasthalfofthecreditforthisbookneedstogotomy
wife,BrigitteKilger-Mattison. Brigittewasresponsible for editingall the mate-
rial, creating all the graphics, and coordinating all the efforts of everyone else
involvedinthisproject.Thisbookcouldnothavebeencompletedwithouther
painstaking attention to detail, her dedication, and her loyalty.
標簽:
Data
Warehousing
Mining
and
上傳時間:
2020-05-27
上傳用戶:shancjb
-
Fundamentals of WiMAX was consciously written to appeal to a broad audience, and to be of
value to anyone who is interested in the IEEE 802.16e standards or wireless broadband networks
more generally. The book contains cutting-edge tutorials on the technical and theoretical under-
pinnings to WiMAX that are not available anywhere else, while also providing high-level over-
views that will be informative to the casual reader.
標簽:
Understanding
Fundamentals
WiMAX
of
上傳時間:
2020-05-27
上傳用戶:shancjb
-
#include<stdio.h>
#define TREEMAX 100
typedef struct BT
{
char data;
BT *lchild;
BT *rchild;
}BT;
BT *CreateTree();
void Preorder(BT *T);
void Postorder(BT *T);
void Inorder(BT *T);
void Leafnum(BT *T);
void Nodenum(BT *T);
int TreeDepth(BT *T);
int count=0;
void main()
{
BT *T=NULL;
char ch1,ch2,a;
ch1='y';
while(ch1=='y'||ch1=='y')
{
printf("\n");
printf("\n\t\t 二叉樹子系統");
printf("\n\t\t*****************************************");
printf("\n\t\t 1---------建二叉樹 ");
printf("\n\t\t 2---------先序遍歷 ");
printf("\n\t\t 3---------中序遍歷 ");
printf("\n\t\t 4---------后序遍歷 ");
printf("\n\t\t 5---------求葉子數 ");
printf("\n\t\t 6---------求結點數 ");
printf("\n\t\t 7---------求樹深度 ");
printf("\n\t\t 0---------返 回 ");
printf("\n\t\t*****************************************");
printf("\n\t\t 請選擇菜單號 (0--7)");
scanf("%c",&ch2);
getchar();
printf("\n");
switch(ch2)
{
case'1':
printf("\n\t\t請按先序序列輸入二叉樹的結點:\n");
printf("\n\t\t說明:輸入結點(‘0’代表后繼結點為空)后按回車。\n");
printf("\n\t\t請輸入根結點:");
T=CreateTree();
printf("\n\t\t二叉樹成功建立!\n");break;
case'2':
printf("\n\t\t該二叉樹的先序遍歷序列為:");
Preorder(T);break;
case'3':
printf("\n\t\t該二叉樹的中序遍歷序列為:");
Inorder(T);break;
case'4':
printf("\n\t\t該二叉樹的后序遍歷序列為:");
Postorder(T);break;
case'5':
count=0;Leafnum(T);
printf("\n\t\t該二叉樹有%d個葉子。\n",count);break;
case'6':
count=0;Nodenum(T);
printf("\n\t\t該二叉樹總共有%d個結點。\n",count);break;
case'7':
printf("\n\t\t該樹的深度為:%d",TreeDepth(T));
break;
case'0':
ch1='n';break;
default:
printf("\n\t\t***請注意:輸入有誤!***");
}
if(ch2!='0')
{
printf("\n\n\t\t按【Enter】鍵繼續,按任意鍵返回主菜單!\n");
a=getchar();
if(a!='\xA')
{
getchar();
ch1='n';
}
}
}
}
BT *CreateTree()
{
BT *t;
char x;
scanf("%c",&x);
getchar();
if(x=='0')
t=NULL;
else
{
t=new BT;
t->data=x;
printf("\n\t\t請輸入%c結點的左子結點:",t->data);
t->lchild=CreateTree();
printf("\n\t\t請輸入%c結點的右子結點:",t->data);
t->rchild=CreateTree();
}
return t;
}
void Preorder(BT *T)
{
if(T)
{
printf("%3c",T->data);
Preorder(T->lchild);
Preorder(T->rchild);
}
}
void Inorder(BT *T)
{
if(T)
{
Inorder(T->lchild);
printf("%3c",T->data);
Inorder(T->rchild);
}
}
void Postorder(BT *T)
{
if(T)
{
Postorder(T->lchild);
Postorder(T->rchild);
printf("%3c",T->data);
}
}
void Leafnum(BT *T)
{
if(T)
{
if(T->lchild==NULL&&T->rchild==NULL)
count++;
Leafnum(T->lchild);
Leafnum(T->rchild);
}
}
void Nodenum(BT *T)
{
if(T)
{
count++;
Nodenum(T->lchild);
Nodenum(T->rchild);
}
}
int TreeDepth(BT *T)
{
int ldep,rdep;
if(T==NULL)
return 0;
else
{
ldep=TreeDepth(T->lchild);
rdep=TreeDepth(T->rchild);
if(ldep>rdep)
return ldep+1;
else
return rdep+1;
}
}
標簽:
二叉樹
子系統
上傳時間:
2020-06-11
上傳用戶:ccccy
-
#include <stdio.h>
#include <stdlib.h>
#define SMAX 100
typedef struct SPNode
{
int i,j,v;
}SPNode;
struct sparmatrix
{
int rows,cols,terms;
SPNode data [SMAX];
};
sparmatrix CreateSparmatrix()
{
sparmatrix A;
printf("\n\t\t請輸入稀疏矩陣的行數,列數和非零元素個數(用逗號隔開):");
scanf("%d,%d,%d",&A.cols,&A.terms);
for(int n=0;n<=A.terms-1;n++)
{
printf("\n\t\t輸入非零元素值(格式:行號,列號,值):");
scanf("%d,%d,%d",&A.data[n].i,&A.data[n].j,&A.data[n].v);
}
return A;
}
void ShowSparmatrix(sparmatrix A)
{
int k;
printf("\n\t\t");
for(int x=0;x<=A.rows-1;x++)
{
for(int y=0;y<=A.cols-1;y++)
{
k=0;
for(int n=0;n<=A.terms-1;n++)
{
if((A.data[n].i-1==x)&&(A.data[n].j-1==y))
{
printf("%8d",A.data[n].v);
k=1;
}
}
if(k==0)
printf("%8d",k);
}
printf("\n\t\t");
}
}
void sumsparmatrix(sparmatrix A)
{
SPNode *p;
p=(SPNode*)malloc(sizeof(SPNode));
p->v=0;
int k;
k=0;
printf("\n\t\t");
for(int x=0;x<=A.rows-1;x++)
{
for(int y=0;y<=A.cols-1;y++)
{
for(int n=0;n<=A.terms;n++)
{
if((A.data[n].i==x)&&(A.data[n].j==y)&&(x==y))
{
p->v=p->v+A.data[n].v;
k=1;
}
}
}
printf("\n\t\t");
}
if(k==1)
printf("\n\t\t對角線元素的和::%d\n",p->v);
else
printf("\n\t\t對角線元素的和為::0");
}
int main()
{
int ch=1,choice;
struct sparmatrix A;
A.terms=0;
while(ch)
{
printf("\n");
printf("\n\t\t 稀疏矩陣的三元組系統 ");
printf("\n\t\t*********************************");
printf("\n\t\t 1------------創建 ");
printf("\n\t\t 2------------顯示 ");
printf("\n\t\t 3------------求對角線元素和");
printf("\n\t\t 4------------返回 ");
printf("\n\t\t*********************************");
printf("\n\t\t請選擇菜單號(0-3):");
scanf("%d",&choice);
switch(choice)
{
case 1:
A=CreateSparmatrix();
break;
case 2:
ShowSparmatrix(A);
break;
case 3:
SumSparmatrix(A);
break;
default:
system("cls");
printf("\n\t\t輸入錯誤!請重新輸入!\n");
break;
}
if (choice==1||choice==2||choice==3)
{
printf("\n\t\t");
system("pause");
system("cls");
}
else
system("cls");
}
}
標簽:
數組
子系統
上傳時間:
2020-06-11
上傳用戶:ccccy
-
對PL/0作以下修改和擴充,并使用測試用例驗證:
(1)修改單詞:不等號# 改為 != ,只有!符號為非法單詞,同時#成為非法
符號。
(2)增加單詞(只實現詞法分析部分):
保留字 else,FOR,STEP,UNTIL,DO,RETURN
運算符 *=(TIMESBECOMES),/=(SLASHBECOMES),&(AND),||(OR)
注釋符 //(NOTE)
(3)增加條件語句的else子句(實現語法語義目標代碼),
要求:寫出相關文法和語法圖,分析語義規則的實現。
標簽:
源碼
實驗報告
上傳時間:
2020-06-30
上傳用戶:12345a
-
FPGA片內FIFO讀寫測試Verilog邏輯源碼Quartus工程文件+文檔說明,使用 FPGA 內部的 FIFO 以及程序對該 FIFO 的數據讀寫操作。FPGA型號Cyclone4E系列中的EP4CE6F17C8,Quartus版本17.1。timescale 1ns / 1ps//////////////////////////////////////////////////////////////////////////////////module fifo_test( input clk, //50MHz時鐘 input rst_n //復位信號,低電平有效 );//-----------------------------------------------------------localparam W_IDLE = 1;localparam W_FIFO = 2; localparam R_IDLE = 1;localparam R_FIFO = 2; reg[2:0] write_state;reg[2:0] next_write_state;reg[2:0] read_state;reg[2:0] next_read_state;reg[15:0] w_data; //FIFO寫數據wire wr_en; //FIFO寫使能wire rd_en; //FIFO讀使能wire[15:0] r_data; //FIFO讀數據wire full; //FIFO滿信號 wire empty; //FIFO空信號 wire[8:0] rd_data_count; wire[8:0] wr_data_count; ///產生FIFO寫入的數據always@(posedge clk or negedge rst_n)begin if(rst_n == 1'b0) write_state <= W_IDLE; else write_state <= next_write_state;endalways@(*)begin case(write_state) W_IDLE: if(empty == 1'b1) //FIFO空, 開始寫FIFO next_write_state <= W_FIFO; else next_write_state <= W_IDLE; W_FIFO: if(full == 1'b1) //FIFO滿 next_write_state <= W_IDLE; else next_write_state <= W_FIFO; default: next_write_state <= W_IDLE; endcaseendassign wr_en = (next_write_state == W_FIFO) ? 1'b1 : 1'b0; always@(posedge clk or negedge rst_n)begin if(rst_n == 1'b0) w_data <= 16'd0; else if (wr_en == 1'b1) w_data <= w_data + 1'b1; else w_data <= 16'd0; end///產生FIFO讀的數據always@(posedge clk or negedge rst_n)begin if(rst_n == 1'b0) read_state <= R_IDLE; else read_state <= next_read_state;endalways@(*)begin case(read_state) R_IDLE: if(full == 1'b1) //FIFO滿, 開始讀FIFO next_read_state <= R_FIFO; else next_read_state <= R_IDLE; R_FIFO: if(empty == 1'b1)
標簽:
fpga
fifo
verilog
quartus
上傳時間:
2021-12-19
上傳用戶:20125101110