将已有numpy数组转化为文件夹图片
时间: 2023-05-20 09:01:11 浏览: 135
可以使用Pillow库中的Image模块来实现将numpy数组转化为图片。具体步骤如下:
1. 导入Pillow库中的Image模块和numpy库。
```python
from PIL import Image
import numpy as np
```
2. 创建一个numpy数组。
```python
arr = np.array([[255, 0, 0], [0, 255, 0], [0, 0, 255]])
```
3. 将numpy数组转化为Pillow库中的Image对象。
```python
img = Image.fromarray(arr.astype('uint8'))
```
4. 保存Image对象为图片文件。
```python
img.save('image.png')
```
这样就可以将numpy数组转化为文件夹图片了。
阅读全文
相关推荐










