Code Planet

为了发现更大的世界


  • 首页

  • 关于

  • 标签

  • 分类

  • 归档

vtk设置actor颜色问题

发表于 2019-02-28 | 分类于 cpp

设置颜色

1
vessel_actors->GetProperty()->SetColor(0.75, 0.75, 0.75);

此时,会显示蓝色
需要设置对应的mapper

1
vessel_mappers->ScalarVisibilityOff();

参考:
http://vtk.1045678.n5.nabble.com/vtkActor-GetProperty-gt-SetColor-not-working-for-me-td5722373.html

vtk处理外部事件

发表于 2019-02-28 | 分类于 cpp

Command方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class CommandSubclass : public vtkCommand
{
public:
vtkTypeMacro(CommandSubclass , vtkCommand);

static CommandSubclass *New()
{
return new CommandSubclass ;
}

void Execute(vtkObject *caller, unsigned long eventId,void *callData)
{
// 过滤按键信息
if (eventId == vtkCommand::KeyPressEvent)
{
// 过滤ctrl
vtkRenderWindowInteractor* interactor =
dynamic_cast<vtkRenderWindowInteractor*>(caller);

if (interactor->GetControlKey())
{
std::string key = interactor->GetKeySym();
if(key == "a")
cout << "ctrl + a" << endl;
}
}
}
};

InteractorStyle方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class MouseInteractorStyleDoubleClick : public vtkInteractorStyleTrackballCamera
{
public:
// 先是interactor style进行处理
// 再是Command进行捕获处理
static MouseInteractorStyleDoubleClick* New();
vtkTypeMacro(MouseInteractorStyleDoubleClick, vtkInteractorStyleTrackballCamera);

MouseInteractorStyleDoubleClick() : NumberOfClicks(0), ResetPixelDistance(5)
{
this->PreviousPosition[0] = 0;
this->PreviousPosition[1] = 0;
}
//http://blog.sina.com.cn/s/blog_5e3a1bbb0100esv3.html
// keydown跟keypress区别
//virtual void OnKeyPress()
//{
// //// Get the keypress
// //vtkRenderWindowInteractor *rwi = this->Interactor;
// //std::string key = rwi->GetKeySym();
// //if (rwi->GetControlKey())
// //{
// // // ctrl+ a
// // if (key == "a")
// // {
// // std::cout << "Ctrl + a" << std::endl;
// // }
// // //rwi->get
// //}
// //vtkInteractorStyleTrackballCamera::OnKeyPress();
//}

virtual void OnLeftButtonUp()
{
vtkRenderWindowInteractor *rwi = this->Interactor;
std::cout << "left mouse" << std::endl;
if (rwi->GetControlKey())
{
std::cout << "Ctrl + left mouse" << std::endl;
}
vtkInteractorStyleTrackballCamera::OnLeftButtonUp();
}


private:
unsigned int NumberOfClicks;
int PreviousPosition[2];
int ResetPixelDistance;
};
vtkStandardNewMacro(MouseInteractorStyleDoubleClick);

libmodbus实现modbus_poll功能

发表于 2019-02-28 | 分类于 cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <modbus.h>
#include <iostream>
#include<stdlib.h>
#include<time.h>

using namespace std;

int main()
{
modbus_t *ctx;
srand((unsigned)time(NULL));

// 创建modbus连接
ctx = modbus_new_tcp("127.0.0.1", 502);

if (ctx == NULL)
{
// 创建失败
fprintf(stderr, "Unable to allocate libmodbus context\n");
return -1;
}

// 设置调试模式
modbus_set_debug(ctx,true);

// 设置连接的slave号,此处为1
int rc = modbus_set_slave(ctx, 1);
if (rc == -1)
{
fprintf(stderr, "Invalid slave ID\n");
modbus_free(ctx);
return -1;
}

// 连接
if (modbus_connect(ctx) == -1)
{
fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
modbus_free(ctx);
return -1;
}

while(1)
{
// 读寄存器
uint16_t* dest= (uint16_t *) malloc(10 * sizeof(uint16_t));
memset(dest, 0, 10);
int rc = modbus_read_registers(ctx, 0, 10, dest);
if (rc == -1)
{
fprintf(stderr, "%s\n", modbus_strerror(errno));
return -1;
}
for(int i = 0; i < 10 ; i++)
{
cout << i << "\t:\t" << dest[i] << endl;
}

Sleep(1000);

// 写寄存器
for(int i=0;i<10;i++)
{
if (dest[i] == 0)
{
dest[i] = rand() %20;
}
else
{
dest[i] *= 3;
dest[i] %= 20 ;
}
}
rc = modbus_write_registers(ctx, 0, 10, dest);
if (rc == -1)
{
fprintf(stderr, "%s\n", modbus_strerror(errno));
return -1;
}
Sleep(1000);
}
modbus_close(ctx);
modbus_free(ctx);
return 0;
}

参考:

[1]. http://www.exbob.com/post/blog/2015-05-24
[2]. http://libmodbus.org/docs/v3.1.4/

可用的Qt设置桌面图标方法

发表于 2019-02-28 | 分类于 cpp

官方解决方案要设置pro文件,一般win下开发使用vs-addin,所以不适用。
网上另一种解决方案是修改vs的vcxproj文件,我试了,没有效果。
亲测可用的方案如下:

1.添加ico文件
2.重命名“appnameico.ico”(不确定是不是必须)
3.新建txt文件,命名为appname.rc,添加

1
IDI_ICON1 ICON DISCARDABLE "appnameico.ico"

4.重新编译生成appname.res文件
5.链接res文件(属性->配置属性->链接器->输入->嵌入托管资源文件),添加生成的res文件(关键步骤)。

[1]http://stackoverflow.com/questions/2949261/howto-set-icon-to-qt-application-created-with-qt-visual-studio-add-in

基于cyptopp库的rsa加解密详解

发表于 2019-02-28 | 分类于 cpp

编译Cryptopp

编译过程没有什么特别,需要注意的是,如果使用dll版本的库,只包含IPS认证的算法,而编译静态链接库则包含全部算法,具体参考[1,2]。

  • cryptopp - This builds the DLL. Please note that if you wish to use Crypto++ as a FIPS validated module, you must use a pre-built DLL that has undergone the FIPS validation process instead of building your own.
  • dlltest - This builds a sample application that only uses the DLL.
  • cryptest Non-DLL-Import Configuration - This builds the full static library along with a full test driver.
  • cryptest DLL-Import Configuration - This builds a static library containing only algorithms not in the DLL, along with a full test driver that uses both the DLL and the static library.

本人编译的lib库大小为50多M。

阅读全文 »

matplotlib基础

发表于 2015-12-29 | 分类于 python

matplotlib基础

1.基本绘图

控制颜色

  • 颜色之间的对应关系为

    b—-blue
    c—-cyan
    g—-green
    k——black
    m—-magenta
    r—-red
    w—-white
    y——yellow

  • 表示颜色的方式:

    a:用全名
    b:16进制如:#FF00FF
    c:RGB或RGBA元组(1,0,1,1)
    d:灰度强度如:‘0.7’

控制线型

  • 符号和线型之间的对应关系
    • 实线
      — 短线
      -. 短点相间线
      : 虚点线

控制标记风格

  • 标记风格有多种:

    . Point marker
    , Pixel marker
    o Circle marker
    v Triangle down marker
    ^ Triangle up marker
    < Triangle left marker
    > Triangle right marker
    1 Tripod down marker
    2 Tripod up marker
    3 Tripod left marker
    4 Tripod right marker
    s Square marker
    p Pentagon marker
    * Star marker
    h Hexagon marker
    H Rotated hexagon D Diamond marker
    d Thin diamond marker
    | Vertical line (vlinesymbol) marker
    _ Horizontal line (hline symbol) marker
    + Plus marker
    x Cross (x) marker

示例代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import pandas as pd
import numpy as np

# 导入matplot库
import matplotlib.pyplot as plt

# 设置输出图像大小
plt.rc('figure', figsize=(10, 5))

# 生成数据
x = np.linspace(0, 2, 10) # [0,2]之间均匀产生10个值
plt.plot(x, x, 'o-', label='linear') # y = x 曲线
plt.plot(x, x ** 2, 'x-', label='quadratic') # y=x^2曲线
plt.legend(loc='best')
plt.title('Linear vs Quadratic progression')
plt.xlabel('Input')
plt.ylabel('Output');
plt.show()

生成结果

Alt text

阅读全文 »

NLTK安装教程

发表于 2015-12-17 | 分类于 NLP

1. 安装nltk

1
sudo pip install nltk

2. 安装nltk_data

  • nltk.downloader自动下载

    1
    python -m nltk.downloader all
  • 网盘链接: http://pan.baidu.com/s/1mgGozzU 密码: axx8

      > 解压地址:
      > (1). C:\nltk_data (Windows); 
      > (2). /usr/local/share/nltk_data (Mac); 
      > (3). and /usr/share/nltk_data (Unix). 
    

NLTK命名实体识别

发表于 2015-12-17 | 分类于 NLP

引例:

NLTK中对于很多自然语言处理应用有着开箱即用的api,但是结果往往让人弄不清楚状况。
下面的例子使用NLTK进行命名实体的识别。第一例中,Apple成功被识别出来,而第二例并未被识别。究竟是什么原因导致这样的结果,接下来一探究竟。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
In [1]: import nltk
In [2]: tokens = nltk.word_tokenize('I am very excited about the next generation of Apple products.')
In [3]: tokens = nltk.pos_tag(tokens)
In [4]: print tokens
[('I', 'PRP'), ('am', 'VBP'), ('very', 'RB'), ('excited', 'JJ'), ('about', 'IN'), ('the', 'DT'), ('next', 'JJ'), ('generation', 'NN'), ('of', 'IN'), ('Apple', 'NNP'), ('products', 'NNS'), ('.', '.')]
In [5]: tree = nltk.ne_chunk(tokens)
In [6]: print tree
(S
I/PRP
am/VBP
very/RB
excited/JJ
about/IN
the/DT
next/JJ
generation/NN
of/IN
(GPE Apple/NNP)
products/NNS
./.)
In [7]: tokens = nltk.word_tokenize('I bought these Apple products today.')
In [8]: tokens = nltk.pos_tag(tokens)
In [9]: print tokens
['I', 'bought', 'these', 'Apple', 'products', 'today', '.']
In [10]: tree = nltk.ne_chunk(tokens)
In [11]: print tree
(S I/PRP bought/VBD these/DT Apple/NNP products/NNS today/NN ./.)

最大熵算法

注意到在上述两个例子Apple这个词被词性标注为NNP(NNP是宾夕法尼亚大学树图资料库II为专有名词,单数)。另外,这两个单词都以大写字母开始。为什么Apple在1例中被标记为GPE(地缘政治实体),而2例未标记?另外,为什么Apple标记为GPE,而不是ORG(组织机构)?

NLTK的命名实体识别是通过使用的MaxEnt分类器。MaxEnt分类器工作有两个原则:1.总是试图保持均匀分布(即最大化熵),2.保持其统计概率与经验数据一致。经验数据来源于语料库,通过手动标记,所以大多数标记数据并不是免费的。NLTK不提供其训练命名实体识别器的语料库(训练数据来自ACE(自动内容抽取))。NLTK所提供的是一个pickle文件(在nltk_data/chunkers/目录下),而这个pickle文件,就是训练好的MaxEnt分类器实例。     

1
2
3
4
5
6
7
➜  maxent_ne_chunker  tree
.
├── english_ace_binary.pickle
├── english_ace_multiclass.pickle
└── PY3
├── english_ace_binary.pickle
└── english_ace_multiclass.pickle

要训练良好的监督学习的算法基于良好的特征。在命名实体识别中,特征可能是这个词是否包含一个大写字母。所以NLTK使用的特征有哪些呢?下面我列出他们:

  • 词的形状(是否包含数字/首字母大写/包含符号)  
  • 词的长度
  • 词的前三个字母
  • 词尾三个字母 
  • 词性标签
  • 词本身 
  • 该词是否存在
  • 该词前面词的词性(前面是否有名词)  
  • 前词词性
  • 后词词性
  • 前词本身 
  • 后词本身 
  • …

下面的代码可以列出NLTK中所使用的标签

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import nltk

# 载入序列化对象
chunker = nltk.data.load('chunkers/maxent_ne_chunker/english_ace_multiclass.pickle')

# 最大熵分类器
maxEnt = chunker._tagger.classifier()

def maxEnt_report():
maxEnt = chunker._tagger.classifier()
print 'These are the labels used by the NLTK\'s NEC...'
print maxEnt.labels()
print ''

print 'These are the most informative features found in the ACE corpora...'
maxEnt.show_most_informative_features()

def ne_report(sentence, report_all=False):

# 词性标记
tokens = nltk.word_tokenize(sentence)
tokens = nltk.pos_tag(tokens)

tags = []
for i in range(0, len(tokens)):
featureset = chunker._tagger.feature_detector(tokens, i, tags)
tag = chunker._tagger.choose_tag(tokens, i, tags)
if tag != 'O' or report_all:
print '\nExplanation on the why the word \'' + tokens[i][0] + '\' was tagged:'
featureset = chunker._tagger.feature_detector(tokens, i, tags)
maxEnt.explain(featureset)
tags.append(tag)

下面的输出报告中列出了NLTK所使用的标签,”I-“,”B-“, “O”前缀的含义为包含/开始/例外(inside/begin/others)标记。当一块开始,第一个词是前缀“B”来表示这个词是一个块的开始。下一个单词,如果它属于同一块,将以”I-“前缀,表示这是块的一部分,而不是开始。如果一个词不属于一块,贴上“O”,这意味着它是在外面。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
➜  test  python dd.py 
These are the labels used by the NLTK's NEC...
['I-GSP', 'B-LOCATION', 'B-GPE', 'I-ORGANIZATION', 'I-PERSON', 'O', 'I-FACILITY', 'I-LOCATION', 'B-PERSON', 'B-FACILITY', 'B-GSP', 'B-ORGANIZATION', 'I-GPE']

These are the most informative features found in the ACE corpora...
10.125 bias==True and label is 'O'
6.631 suffix3=='day' and label is 'O'
-6.207 bias==True and label is 'I-GSP'
5.628 prevtag=='O' and label is 'O'
-4.740 shape=='upcase' and label is 'O'
4.106 shape+prevtag=='<function shape at 0x8bde0d4>+O' and label is 'O'
-3.994 shape=='mixedcase' and label is 'O'
3.992 pos+prevtag=='NNP+B-PERSON' and label is 'I-PERSON'
3.890 prevtag=='I-ORGANIZATION' and label is 'I-ORGANIZATION'
3.879 shape+prevtag=='<function shape at 0x8bde0d4>+I-ORGANIZATION' and label is 'I-ORGANIZATION'

Note:

  • GPE is Geo-Political Entity
  • GSP is Geo-Socio-Political group

例1输出:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Explanation on the why the word 'Apple' was tagged:
Feature B-GPE O B-ORGAN B-GSP
--------------------------------------------------------------------------------
prevtag=='O' (1) 3.767
shape=='upcase' (1) 2.701
pos+prevtag=='NNP+O' (1) 2.254
en-wordlist==False (1) 2.095
label is 'B-GPE' (1) -2.005
bias==True (1) -1.975
prevword=='of' (1) 0.742
pos=='NNP' (1) 0.681
nextpos=='nns' (1) 0.661
prevpos=='IN' (1) 0.311
wordlen==5 (1) 0.113
nextword=='products' (1) 0.060
bias==True (1) 10.125
prevtag=='O' (1) 5.628
shape=='upcase' (1) -4.740
prevpos=='IN' (1) -1.668
label is 'O' (1) -1.075
pos=='NNP' (1) -1.024
suffix3=='ple' (1) 0.797
en-wordlist==False (1) 0.698
wordlen==5 (1) -0.449
prevword=='of' (1) -0.217
nextpos=='nns' (1) 0.104
prefix3=='app' (1) 0.089
pos+prevtag=='NNP+O' (1) 0.011
nextword=='products' (1) 0.005
prevtag=='O' (1) 3.389
pos+prevtag=='NNP+O' (1) 1.725
bias==True (1) 0.955
en-wordlist==False (1) 0.837
label is 'B-ORGANIZATION' (1) 0.718
nextpos=='nns' (1) 0.365
wordlen==5 (1) -0.351
pos=='NNP' (1) 0.174
prevpos=='IN' (1) -0.139
prevword=='of' (1) 0.131
prefix3=='app' (1) -0.126
shape=='upcase' (1) -0.084
suffix3=='ple' (1) -0.077
prevtag=='O' (1) 2.925
pos+prevtag=='NNP+O' (1) 2.213
shape=='upcase' (1) 0.929
en-wordlist==False (1) 0.891
bias==True (1) -0.592
label is 'B-GSP' (1) -0.565
prevpos=='IN' (1) 0.410
nextpos=='nns' (1) 0.399
pos=='NNP' (1) 0.393
prevword=='of' (1) 0.184
wordlen==5 (1) 0.177
---------------------------------------------------------------------------------
TOTAL: 9.406 8.283 7.515 7.366
PROBS: 0.453 0.208 0.122 0.110

最后一行中列出的概率加起来加起来是0.893,而非1。这是因为只输出概率最大的四类标签。

例2输出:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Explanation on the why the word 'Apple' was tagged:
Feature O B-GPE B-ORGAN B-LOCAT
--------------------------------------------------------------------------------
bias==True (1) 10.125
prevtag=='O' (1) 5.628
shape=='upcase' (1) -4.740
label is 'O' (1) -1.075
pos=='NNP' (1) -1.024
suffix3=='ple' (1) 0.797
en-wordlist==False (1) 0.698
prevpos=='DT' (1) 0.585
wordlen==5 (1) -0.449
nextpos=='nns' (1) 0.104
prefix3=='app' (1) 0.089
prevword=='these' (1) -0.024
pos+prevtag=='NNP+O' (1) 0.011
nextword=='products' (1) 0.005
prevtag=='O' (1) 3.767
shape=='upcase' (1) 2.701
pos+prevtag=='NNP+O' (1) 2.254
en-wordlist==False (1) 2.095
label is 'B-GPE' (1) -2.005
bias==True (1) -1.975
pos=='NNP' (1) 0.681
nextpos=='nns' (1) 0.661
prevpos=='DT' (1) -0.181
wordlen==5 (1) 0.113
nextword=='products' (1) 0.060
prevtag=='O' (1) 3.389
pos+prevtag=='NNP+O' (1) 1.725
bias==True (1) 0.955
en-wordlist==False (1) 0.837
label is 'B-ORGANIZATION' (1) 0.718
prevpos=='DT' (1) -0.494
nextpos=='nns' (1) 0.365
wordlen==5 (1) -0.351
pos=='NNP' (1) 0.174
prefix3=='app' (1) -0.126
shape=='upcase' (1) -0.084
suffix3=='ple' (1) -0.077
prevword=='these' (1) 0.067
prevtag=='O' (1) 2.682
label is 'B-LOCATION' (1) -2.038
pos+prevtag=='NNP+O' (1) 1.724
shape=='upcase' (1) 1.275
prefix3=='app' (1) 1.169
bias==True (1) 0.747
prevpos=='DT' (1) 0.745
pos=='NNP' (1) 0.616
en-wordlist==False (1) -0.309
nextpos=='nns' (1) 0.151
wordlen==5 (1) 0.041
---------------------------------------------------------------------------------
TOTAL: 10.730 8.171 7.095 6.802
PROBS: 0.697 0.118 0.056 0.046

由此:1和2中在GPE识别中唯一的区别在于下面三行:

prevword==’of’ (1) 0.742
prevpos==’IN’ (1) 0.311
prevpos==’DT’ (1) -0.181

可见,1中
1中的Apple被识别为B-GPE,而2中的Apple被识别为O。

引用:

[1] http://www.nltk.org/book/ch07.html
[2] http://spark-public.s3.amazonaws.com/nlp/slides/Information_Extraction_and_Named_Entity_Recognition_v2.pdf
[3] http://www.mattshomepage.com/#/blog/feb2013/liftingthehood

Titan连接Hbase后端

发表于 2015-12-17 | 分类于 big data

步骤

1.启动hbase

1
2
➜  hbase-1.1.2  ./bin/start-hbase.sh
starting master, logging to /home/luxh/hbase/hbase-1.1.2/bin/../logs/hbase-luxh-master-ubuntu.out

2.启动gremlin:连接本地hbase时不需要显式加入host

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
➜  titan-1.0.0-hadoop1  bin/gremlin.sh


\,,,/
(o o)
-----oOOo-(3)-oOOo-----
plugin activated: aurelius.titan
plugin activated: tinkerpop.server
plugin activated: tinkerpop.utilities
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/luxh/titan/titan-1.0.0-hadoop1/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/luxh/titan/titan-1.0.0-hadoop1/lib/logback-classic-1.1.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
15:04:30 INFO org.apache.tinkerpop.gremlin.hadoop.structure.HadoopGraph - HADOOP_GREMLIN_LIBS is set to: /home/luxh/titan/titan-1.0.0-hadoop1/lib
plugin activated: tinkerpop.hadoop
plugin activated: tinkerpop.tinkergraph
gremlin>
gremlin> TitanGraph graph = TitanFactory.build().set("storage.backend", "hbase").open();
==>standardtitangraph[hbase:[127.0.0.1]]
gremlin>

连接远程hbase时,语句如下更改为如下方式

1
TitanGraph g = TitanFactory.build().set("storage.backend", "hbase").set("storage.hostname", "77.77.77.77, 77.77.77.78, 77.77.77.79").open();

引用

[1]. http://s3.thinkaurelius.com/docs/titan/1.0.0/hbase.html

Numpy包数据处理

发表于 2015-11-26 | 分类于 data science

1. Numpy包导入

1
>>> import numpy as np

2. 生成矩阵

  • zeros 0矩阵
  • ones 1矩阵
  • identity 单位矩阵
  • eye 对角矩阵
  • random 随机矩阵
  • empty 依据内存生成矩阵
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
>>> a = np.array([1, 2, 3])
>>> print a
[1 2 3]
>>> np.zeros(5)
array([ 0., 0., 0., 0., 0.])
>>> np.ones(shape=(3,4),dtype=np.int32)
array([[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]], dtype=int32)
>>> print np.identity(3)
[[ 1. 0. 0.]
[ 0. 1. 0.]
[ 0. 0. 1.]]
>>> print np.eye(3,5)
[[ 1. 0. 0. 0. 0.]
[ 0. 1. 0. 0. 0.]
[ 0. 0. 1. 0. 0.]]
>>> print np.random.rand(3,4)
[[ 0.40974346 0.09968249 0.32264537 0.78815716]
[ 0.52959935 0.74650259 0.36604339 0.80450681]
[ 0.07308854 0.83747867 0.18952243 0.03182399]]
>>> x = np.empty(shape=(3,3),dtype=np.int16)
>>> print x
[[ 6088 5994 32645]
[ 0 -16048 630]
[ 0 0 32]]
阅读全文 »
1234…12
Lu Xiaohua

Lu Xiaohua

116 日志
33 分类
86 标签
GitHub E-Mail
© 2019 Lu Xiaohua
由 Hexo 强力驱动 v3.8.0
|
主题 – NexT.Muse v7.0.0