python 实现单通道转3通道

yipeiwu_com6年前Python基础

下面有两种方法都可以:

import numpy as np
a=np.asarray([[10,20],[101,201]])

# a=a[:,:,np.newaxis]
# print(a.shape)
# b= a.repeat([3],axis=2)
# print(b.shape,b)

image = np.expand_dims(a, axis=2)
image = np.concatenate((image, image, image), axis=-1)

print(image)
axis=-1就是最后一个通道

以上这篇python 实现单通道转3通道就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python图的深度优先和广度优先算法实例分析

本文实例讲述了python图的深度优先和广度优先算法。分享给大家供大家参考,具体如下: 首先有一个概念:回溯 回溯法(探索与回溯法)是一种选优搜索法,按选优条件向前搜索,以达到目标。但当...

python+selenium实现简历自动刷新的示例代码

python+selenium实现简历自动刷新的示例代码

本文用到的文件的下载地址 百度网盘链接: https://pan.baidu.com/s/1tmpdEfAZKff5TOMAitUXqQ 提取码: e6at 1 安装Python 和 s...

Python-Tkinter Text输入内容在界面显示的实例

使用Tkinter(py2.7)text文本框中输入内容在界面中显示–较为规整的代码: import Tkinter as tk class Window: def __init...

Python文件的读写和异常代码示例

一、从文件中读取数据 #!/usr/bin/env python with open('pi') as file_object: contents = file_object.r...

Python3实现从文件中读取指定行的方法

本文实例讲述了Python3实现从文件中读取指定行的方法。分享给大家供大家参考。具体实现方法如下: # Python的标准库linecache模块非常适合这个任务 import li...