如果您对Python-将NumPy数组转储到csv文件中感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于Python-将NumPy数组转储到csv文件中的详细内容,我们还将为
如果您对Python-将NumPy数组转储到csv文件中感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于Python-将NumPy数组转储到csv文件中的详细内容,我们还将为您解答将numpy数组转换为图片的相关问题,并且为您提供关于MySQL转储到CSV文本文件中,列名在顶部?[复制]、python numpy数组的numpy数组、python – 如何将numpy数组流式传输到pyaudio流?、python – 将boolean numpy数组转换为枕头图像的有价值信息。
本文目录一览:- Python-将NumPy数组转储到csv文件中(将numpy数组转换为图片)
- MySQL转储到CSV文本文件中,列名在顶部?[复制]
- python numpy数组的numpy数组
- python – 如何将numpy数组流式传输到pyaudio流?
- python – 将boolean numpy数组转换为枕头图像
Python-将NumPy数组转储到csv文件中(将numpy数组转换为图片)
有没有办法将NumPy数组转储到CSV文件中?我有一个2D NumPy数组,需要以人类可读的格式转储它。
答案1
小编典典numpy.savetxt
将数组保存到文本文件。
import numpya = numpy.asarray([ [1,2,3], [4,5,6], [7,8,9] ])numpy.savetxt("foo.csv", a, delimiter=",")
MySQL转储到CSV文本文件中,列名在顶部?[复制]
我使用以下SQL代码段将表转储为CSV文本文件:
SELECT * FROM brand INTO OUTFILE“ e:/brand.csv”字段以’,’结尾,’‘’以’\ n’结尾;
但是,这种方法不会在CSV文件的开头添加列名。我的问题是如何也选择所有列/字段名称,就像phpMyAdmin在导出表并选择“在第一行中放入字段名称”时所做的一样。
python numpy数组的numpy数组
我在创建numpy数组的numpy数组时遇到问题。我将在一个循环中创建它:
a=np.array([])
while(...):
...
b= //a numpy array generated
a=np.append(a,b)
...
所需结果:
[[1,5,3],[9,10,1],...,[4,8,6]]
实际结果:
[1,3,9,1,... 4,6]
可能吗?我不知道数组的最终尺寸,因此无法使用固定尺寸对其进行初始化。
python – 如何将numpy数组流式传输到pyaudio流?
解决方法
# Open stream with correct settings stream = self.p.open(format=pyaudio.paFloat32,channels=CHANNELS,rate=48000,output=True,output_device_index=1 ) # Assuming you have a numpy array called samples data = samples.astype(np.float32).tostring() stream.write(data)
我使用这种方法,它对我来说很好.如果您需要同时录制,那么这将无效.
python – 将boolean numpy数组转换为枕头图像
from PIL import Image import numpy from skimage.color import rgb2gray from skimage.filters import threshold_sauvola im = Image.open("test.jpg") pix = numpy.array(im) img = rgb2gray(pix) window_size = 25 thresh_sauvola = threshold_sauvola(img,window_size=window_size) binary_sauvola = img > thresh_sauvola
这给出了以下结果:
输出是一个numpy数组,此图像的数据类型是bool
[[ True True True ... True True True] [ True True True ... True True True] [ True True True ... True True True] ... [ True True True ... True True True] [ True True True ... True True True] [ True True True ... True True True]]
问题是我需要使用以下代码行将此数组转换回PIL图像:
image = Image.fromarray(binary_sauvola)
这使得图像看起来像这样:
我也尝试将数据类型从bool更改为uint8,但之后我将得到以下异常:
AttributeError: 'numpy.ndarray' object has no attribute 'mask'
到目前为止,我还没有找到一个解决方案来获得看起来像阈值结果的PIL图像.
解决方法
import numpy as np from PIL import Image # The standard work-around: first convert to greyscale def img_grey(data): return Image.fromarray(data * 255,mode='L').convert('1') # Use .frombytes instead of .fromarray. # This is >2x faster than img_grey def img_frombytes(data): size = data.shape[::-1] databytes = np.packbits(data,axis=1) return Image.frombytes(mode='1',size=size,data=databytes)
另见Error Converting PIL B&W images to Numpy Arrays.
今天关于Python-将NumPy数组转储到csv文件中和将numpy数组转换为图片的介绍到此结束,谢谢您的阅读,有关MySQL转储到CSV文本文件中,列名在顶部?[复制]、python numpy数组的numpy数组、python – 如何将numpy数组流式传输到pyaudio流?、python – 将boolean numpy数组转换为枕头图像等更多相关知识的信息可以在本站进行查询。
本文标签: