0%

100 numpy exercises

This is a collection of exercises that have been collected in the numpy mailing list, on stack
overflow
and in the numpy documentation. The goal of this collection is to offer a quick reference for both old
and new
users but also to provide a set of exercises for those who teach.

If you find an error or think you’ve a better way to
solve some of them, feel
free to open an issue at https://github.com/rougier/numpy-100.
File automatically generated. See the documentation to update questions/answers/hints programmatically.

阅读全文 »

趁着线性代数的知识还热乎,简短的写了个矩阵类的demo,目前实现了

  • 矩阵的构造
  • 矩阵的运算(+ - * =)
  • 矩阵的读写

需不断更新…(对角矩阵、求矩阵的逆、伴随矩阵、对称矩阵、特征值与特征向量、矩阵相似判断、是否可对角化、二次型等实际需要时再继续学习)

阅读全文 »

At the film’s beginning, Hank (Paul Dano) prepares to commit suicide on a deserted island, and suddenly a corpse is washed ashore by the waves. Interestingly, this corpse is farting every second, which disturbs Hank’s suicide. Hence Hank goes ahead and has a look. Then Hank stops killing himself, dragging the dead man named Manny by Hank, into a cave. It is so funny that Harry Porter’s actor, Daniel Radcliffe, portrays the never-stop-farted corpse so that reports tell the story bluntly: Daniel Radcliffe farts a lot in this movie.

阅读全文 »

求next数组

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
int* getNext(string str) {
int str_len = str.size();
int* next = new int[str_len];//为申请next数组申请内存空间
next[0] = 0;
next[1] = 0;
int prefix = 0;
int index = 2;
//比较前缀与后缀
while(index<str_len) {
if (str[index-1] == str[prefix]) {
prefix++;
next[index] = prefix;
index++;
}
else {
if (prefix == 0) {
next[index] = prefix;
index++;
}
else
prefix = next[prefix-1];
}
}
return next;
}

kmp算法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int KMP(string pattern, string str) {
//得到next数组
int* next = getNext(pattern);
int i = 0, j = 0;//两个索引分别代表主串和模式串的下标
//主串与模式进行比较
while (i < str.size()) {
//字符匹配则主串模式串索引均后移
if (str[i] == pattern[j]||j==0) {
i++;j++;
if (j >= pattern.size()) {
break;
}
}
//不匹配,主串索引不变,模式串索引根据next数组作相应的改变
else {

j = next[j];
}
}
delete [] next;
if (j == pattern.size())
return i - pattern.size();
else return -1;
}

本文用C++阐述十大排序算法的升降序实现方法。

  • 交换排序(冒泡,快排)
  • 插入排序(简单插入,希尔)
  • 选择排序、堆排序
  • 归并排序
  • 基数排序,计数排序,桶排序
阅读全文 »

本文从五个方面详述C++11特性:

  • 关键字与变量的使用
  • 面向对象特性(委托构造函数,继承构造函数,可调用对象包装器、邦定器,lambda表达式等)
  • 移动语义
  • 智能指针
  • 多线程
阅读全文 »

本文讲述树的遍历各种操作,层次遍历,前中后三种次序的遍历的迭代实现方式。其中包含力扣的相关题目。

开篇之前,先通过先序遍历的次序构建二叉树。(本片代码以二叉树为主,故多叉树结构暂不编写)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//二叉树结构体
struct BiTree {
char val;
BiTree* left=NULL;
BiTree* right=NULL;
};
//先序创建二叉树
void createTree(BiTree* &root) {
char ch;
cin >> ch;
if (ch != 'x') {//x表示为空结点
root = new BiTree;
root->val = ch;
createTree(root->left);
createTree(root->right);

}
else root = NULL;
}
阅读全文 »

本文记录学习0-1背包问题时的总结,详细介绍了对背包问题的暴力解法,二维数组的思路以及滚动数组思路的理解,并给出详细注释与代码。

阅读全文 »

定时任务调度

  • crontab 定时任务设置

​ -e 编辑crontab定时任务

​ -l 查询crontab任务

​ -r 删除当前用户所有的crontab任务

阅读全文 »