Skip to content

Commit 96d413e

Browse files
committed
keng
1 parent b3d76db commit 96d413e

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5108,6 +5108,68 @@ array = [5, 7, 9]
51085108
g = (x for x in [1,3,5] if [5,7,9].count(x) > 0)
51095109
```
51105110
5111+
5112+
5113+
#### 13 创建空集合错误
5114+
5115+
这是Python的一个集合:`{1,3,5}`,它里面没有重复元素,在去重等场景有重要应用。下面这样创建空集合是错误的:
5116+
5117+
```python
5118+
empty = {} #NO!
5119+
```
5120+
5121+
cpython会解释它为字典
5122+
5123+
使用内置函数`set()`创建空集合:
5124+
5125+
```python
5126+
empty = set() #YES!
5127+
```
5128+
5129+
5130+
5131+
#### 14 pyecharts传入Numpy数据绘图失败
5132+
5133+
echarts使用广泛,echarts+python结合后的包:pyecharts,同样可很好用,但是传入Numpy的数据,像下面这样绘图会失败:
5134+
5135+
```python
5136+
from pyecharts.charts import Bar
5137+
import pyecharts.options as opts
5138+
import numpy as np
5139+
c = (
5140+
Bar()
5141+
.add_xaxis([1, 2, 3, 4, 5])
5142+
# 传入Numpy数据绘图失败!
5143+
.add_yaxis("商家A", np.array([0.1, 0.2, 0.3, 0.4, 0.5]))
5144+
)
5145+
5146+
c.render()
5147+
```
5148+
5149+
![image-20200129164119080](./img/image-20200129164119080.png)
5150+
5151+
由此可见pyecharts对Numpy数据绘图不支持,传入原生Python的list:
5152+
5153+
```python
5154+
from pyecharts.charts import Bar
5155+
import pyecharts.options as opts
5156+
import numpy as np
5157+
c = (
5158+
Bar()
5159+
.add_xaxis([1, 2, 3, 4, 5])
5160+
# 传入Python原生list
5161+
.add_yaxis("商家A", np.array([0.1, 0.2, 0.3, 0.4, 0.5]).tolist())
5162+
)
5163+
5164+
c.render()
5165+
```
5166+
5167+
![image-20200129164339971](./img/image-20200129164339971.png)
5168+
5169+
5170+
5171+
5172+
51115173
### 七、 Python第三方包
51125174
51135175
#### 1 优化代码异常输出包

img/image-20200129164119080.png

9.32 KB
Loading

img/image-20200129164339971.png

16.5 KB
Loading

0 commit comments

Comments
 (0)