們知道在java script中 for 用來實現循環結構,而for...in 用來實現遍歷,for...of用來對象迭代遍歷。
與其他開發語言相同,JS中for用來實現循環結構之一,
for ([initialization]; [condition]; [final-expression]) {
statement
}
for(let i=1;i<=10;i++){
console.log("i=",i);
}
執行結果:
break關鍵詞用戶終止循環
for(let i=1;i<=10;i++){
if(i>5)
break;
console.log("i=",i);
}
循環到第5次終止循環。
執行結果:
i=1
i=2
i=3
i=4
i=5
continue關鍵詞用戶跳過本次循環,繼續下一次
for(let i=1;i<=10;i++){
if(i % 2===0 ) continue;
console.log("i=",i);
}
如果i是偶數跳過,執行下一次循環,輸出i為奇數
i=1
i=3
i=5
i=7
i=9
for循環是js中基礎的循環結構,適用于任何情況,而for...in和for...of則更適合于不同的應用場景。
for...in循環遍歷對象的所有可枚舉屬性。什么是可枚舉呢?你可以理解為可枚舉就是可表現為鍵值對的對象,for...in枚舉得到的是鍵值對的鍵值。
objs={mp_v:"可視化",mp_a:"低代碼",mp_name:"有效云"};
for(let objk in objs){
console.log("key:",objk,"值:",objs[objk]);
}
//執行結果:
key: mp_v 值: 可視化
key: mp_a 值: 低代碼
key: mp_name 值: 有效云
從上例中可以看到,for...in 循環枚舉得到了鍵值對 key-value中的key屬性值,檢索適用鍵值對的值,將鍵視為數組中的索引并將其放在方括號 ->objs[key]中,如上面代碼中的:objs[objk]。
注意:一維數組也可以理解為鍵值對,key即為數組的索引,但是for...in枚舉是無序的,無法保證枚舉得到的順序,所以不建議使用for...in用來枚舉數組,應該使用for,for...of 或for each 來遍歷數組。
ES6引入for...of之后,它已經成為廣大開發者們常用以迭代枚舉對象的方法。
pmname="有效云開發平臺"
for(letter of pmname){
console.log(letter);
}
//執行結果:
有
效
云
開
發
平
臺
上例使用for...of枚舉了字符串中的每個字符,我們注意到,for...of是有序的,這與for...in不同。
for...of可以用來迭代枚舉任何,除字符串外還可以是數組、對象等。
const arrA=[1,2,3,4,5,6];
for( let v of arrA ){
console.log(v);
}
//執行結果:
1
2
3
4
5
6
上面代碼使用 for...of 遍歷了數組arrA,接下來使用for..of迭代對象。
objs={mp_v:"可視化",mp_a:"低代碼",mp_name:"有效云"};
for(const [k,v] of Object.entries(objs)){
console.log("key:",k,"val:",v);
}
// key: mp_v val: 可視化
// key: mp_a val: 低代碼
// key: mp_name val: 有效云
通過這個示例,我們看到在遍歷對象時,通過[v,k],同時獲得鍵值對的鍵和值。
感謝閱讀,歡迎關注有效云開發平臺。
affe的安裝筆記 Ubuntu16.04
跑實驗用過一次caffe,光安裝就用了一周,經歷了各種錯誤,真的好難安裝,記錄下最后成功安裝的方法,希望給大家安裝時提供參考。
1、下載安裝所需的包,例如anaconda,numpy ,protobuf,opencv,cython, scikit-image等
opencv使用
conda install opencv
直接使用 conda install caffe-gpu安裝好所需的環境再使用源碼編譯,進行下面的步驟
再 使用conda uninstall caffe-gpu 去掉這個包,裝上需要的環境,但是這個包不能直接使用(我也不知道原因)。
2、下載caffe
git clone https://github.com/BVLC/caffe.git
3、更改makefile.config
USE_CUDNN :=1
USE_OPENCV :=0 OPENCV_VERSION :=3
CUDA_DIR :=/usr/local/cuda_env/cuda-8.0
ANACONDA_HOME :=$(HOME)/anaconda3/envs/caffe PYTHON_INCLUDE :=$(ANACONDA_HOME)/include \ $(ANACONDA_HOME)/include/python3.6m\ $(ANACONDA_HOME)/lib/python3.6/site-packages/numpy/core/include PYTHON_LIB :=$(ANACONDA_HOME)/lib
INCLUDE_DIRS :=$(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial LIBRARY_DIRS :=$(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial/
完整的makefile.config
## Refer to http://caffe.berkeleyvision.org/installation.html # Contributions simplifying and improving our build system are welcome! # cuDNN acceleration switch (uncomment to build with cuDNN). USE_CUDNN :=1 # CPU-only switch (uncomment to build without GPU support). # CPU_ONLY :=1 # uncomment to disable IO dependencies and corresponding data layers USE_OPENCV :=0 # USE_LEVELDB :=0 # USE_LMDB :=0 # uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary) # You should not set this flag if you will be reading LMDBs with any # possibility of simultaneous read and write # ALLOW_LMDB_NOLOCK :=1 # Uncomment if you're using OpenCV 3 OPENCV_VERSION :=3 # To customize your choice of compiler, uncomment and set the following. # N.B. the default for Linux is g++ and the default for OSX is clang++ # CUSTOM_CXX :=g++ # CUDA directory contains bin/ and lib/ directories that we need. CUDA_DIR :=/usr/local/cuda_env/cuda-8.0 # On Ubuntu 14.04, if cuda tools are installed via # "sudo apt-get install nvidia-cuda-toolkit" then use this instead: # CUDA_DIR :=/usr # CUDA architecture setting: going with all of them. # For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility. # For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility. # For CUDA >=9.0, comment the *_20 and *_21 lines for compatibility. CUDA_ARCH :=-gencode arch=compute_20,code=sm_20 \ -gencode arch=compute_20,code=sm_21 \ -gencode arch=compute_30,code=sm_30 \ -gencode arch=compute_35,code=sm_35 \ -gencode arch=compute_50,code=sm_50 \ -gencode arch=compute_52,code=sm_52 \ -gencode arch=compute_60,code=sm_60 \ -gencode arch=compute_61,code=sm_61 \ -gencode arch=compute_61,code=compute_61 # BLAS choice: # atlas for ATLAS (default) # mkl for MKL # open for OpenBlas BLAS :=atlas # Custom (MKL/ATLAS/OpenBLAS) include and lib directories. # Leave commented to accept the defaults for your choice of BLAS # (which should work)! # BLAS_INCLUDE :=/path/to/your/blas # BLAS_LIB :=/path/to/your/blas # Homebrew puts openblas in a directory that is not on the standard search path # BLAS_INCLUDE :=$(shell brew --prefix openblas)/include # BLAS_LIB :=$(shell brew --prefix openblas)/lib # This is required only if you will compile the matlab interface. # MATLAB directory should contain the mex binary in /bin. # MATLAB_DIR :=/usr/local # MATLAB_DIR :=/Applications/MATLAB_R2012b.app # NOTE: this is required only if you will compile the python interface. # We need to be able to find Python.h and numpy/arrayobject.h. #PYTHON_INCLUDE :=/usr/include/python2.7 \ # /usr/lib/python2.7/dist-packages/numpy/core/include # Anaconda Python distribution is quite popular. Include path: # Verify anaconda location, sometimes it's in root. ANACONDA_HOME :=$(HOME)/anaconda3/envs/caffe PYTHON_INCLUDE :=$(ANACONDA_HOME)/include \ $(ANACONDA_HOME)/include/python3.6m\ $(ANACONDA_HOME)/lib/python3.6/site-packages/numpy/core/include # Uncomment to use Python 3 (default is Python 2) # PYTHON_LIBRARIES :=boost_python3 python3.5m # PYTHON_INCLUDE :=/usr/include/python3.5m \ # /usr/lib/python3.5/dist-packages/numpy/core/include # We need to be able to find libpythonX.X.so or .dylib. # PYTHON_LIB :=/usr/lib PYTHON_LIB :=$(ANACONDA_HOME)/lib # Homebrew installs numpy in a non standard path (keg only) # PYTHON_INCLUDE +=$(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include # PYTHON_LIB +=$(shell brew --prefix numpy)/lib # Uncomment to support layers written in Python (will link against Python libs) # WITH_PYTHON_LAYER :=1 # Whatever else you find you need goes here. INCLUDE_DIRS :=$(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial LIBRARY_DIRS :=$(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial/ # If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies # INCLUDE_DIRS +=$(shell brew --prefix)/include # LIBRARY_DIRS +=$(shell brew --prefix)/lib # NCCL acceleration switch (uncomment to build with NCCL) # https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0) # USE_NCCL :=1 # Uncomment to use `pkg-config` to specify OpenCV library paths. # (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.) # USE_PKG_CONFIG :=1 # N.B. both build and distribute dirs are cleared on `make clean` BUILD_DIR :=build DISTRIBUTE_DIR :=distribute # Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171 # DEBUG :=1 # The ID of the GPU that 'make runtest' will use to run unit tests. TEST_GPUID :=0 # enable pretty build (comment to see full commands) Q ?=@
4、更改makefile,更改這一行
LIBRARIES +=opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs
5、編譯caffe
cd caffe make all -j8 make pycaffe
6、更改.bashrc路徑
export PYTHONPATH="/home/usrname/caffe/python:$PYTHONPATH"
7、完整安裝caffe路徑(這個私人設置,不做參考)
# add for use caffe copy from jhyang export LD_LIBRARY_PATH="/usr/local/cuda_env/cuda-8.0/lib64:/usr/local/cuda_env/cudnn-v5.1-for-cuda8.0/lib64:/usr/local/cuda_env/cudnn-v6.0-for-cuda8.0/lib64:/usr/local/cuda_env/cuda-9.0/lib64:/usr/local/cuda_env/cudnn-v7.0-for-cuda9.0/lib64" export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/bin:/bin:/usr/sbin:/sbin" export LIBRARY_PATH="/usr/local/cuda_env/cuda-8.0/lib64:/usr/local/cuda_env/cudnn-v5.1-for-cuda8.0/lib64:/usr/local/cuda_env/cudnn-v6.0-for-cuda8.0/lib64:/usr/local/cuda_env/cuda-9.0/lib64:/usr/local/cuda_env/cudnn-v7.0-for-cuda9.0/lib64" export PYTHONPATH="/home/usr/caffe/python:$PYTHONPATH" export CPATH=$CPATH:/usr/local/cuda_env/cudnn-v6.0-for-cuda8.0/include:/usr/include/hdf5/serial/hdf5.h export CPATH=/usr/local/cuda_env/cudnn-v5.1-for-cuda8.0/include:/usr/local/cuda_env/cudnn-v6.0-for-cuda8.0/include:/usr/local/cuda_env/cudnn-v7.0-for-cuda9.0/include
8、測試使用
么是JavaScript
JavaScript是一種基于對象和事件驅動的、并具有安全性能的腳本語言,已經被廣泛用于Web應用開發,常用來為網頁添加各式各樣的動態功能,為用戶提供更流暢美觀的瀏覽效果。通常JavaScript腳本是通過嵌入在HTML中來實現自身的功能的。
JavaScript特點
是一種解釋性腳本語言(代碼不進行預編譯)。
主要用來向HTML(標準通用標記語言下的一個應用)頁面添加交互行為。
可以直接嵌入HTML頁面,但寫成單獨的js文件有利于結構和行為的分離。
跨平臺特性,在絕大多數瀏覽器的支持下,可以在多種平臺下運行(如Windows、Linux、Mac、Android、iOS等)。
JavaScript組成
JavaScript日常用途
1、嵌入動態文本于HTML頁面。
2、對瀏覽器事件做出響應。
3、讀寫HTML元素。
4、在數據被提交到服務器之前驗證數據。
5、檢測訪客的瀏覽器信息。
6、控制cookies,包括創建和修改等。
7、基于Node.js技術進行服務器端編程。
JavaScript的基本結構
<script type="text/javascript"> <!— JavaScript 語句; —> </script >
示例:
…… <title>初學JavaScript</title> </head> <body> <script type="text/javascript"> document.write("初學JavaScript"); document.write("<h1>Hello,JavaScript</h1>"); </script> </body> </html>
<script>…</script>可以包含在文檔中的任何地方,只要保證這些代碼在被使用前已讀取并加載到內存即可
JavaScript的執行原理
網頁中引用JavaScript的方式
1、使用<script>標簽
2、外部JS文件
<script src="export.js" type="text/javascript"></script>
3.直接在HTML標簽中
<input name="btn" type="button" value="彈出消息框" onclick="javascript:alert('歡迎你');"/>
JavaScript核心語法:
1. 變量
①先聲明變量再賦值
var width; width=5; var - 用于聲明變量的關鍵字 width - 變量名
②同時聲明和賦值變量
var catName="皮皮"; var x, y, z=10;
③不聲明直接賦值【一般不使用】
width=5;
變量可以不經聲明而直接使用,但這種方法很容易出錯,也很難查找排錯,不推薦使用。
2. 數據類型
①undefined:示例:var width;
變量width沒有初始值,將被賦予值undefined
②null:表示一個空值,與undefined值相等
③number:
var iNum=23; //整數
var iNum=23.0; //浮點數
④Boolean:true和false 但是JS會把他們解析成1;0
⑤String:一組被引號(單引號或雙引號)括起來的文本 var string1="This is a string";
3. typeof運算符
typeof檢測變量的返回值;typeof運算符返回值如下:
①undefined:變量被聲明后,但未被賦值.
②string:用單引號或雙引號來聲明的字符串。
③boolean:true或false。
④number:整數或浮點數。
⑤object:javascript中的對象、數組和null。
*請認真填寫需求信息,我們會在24小時內與您取得聯系。