我有1000个RGB图像(64X64),我想将其转换为(m,n)数组.
我用这个:
import numpy as np
from skdata.mnist.views import OfficialImageClassification
from matplotlib import pyplot as plt
from PIL import Image
import glob
import cv2
x_data = np.array( [np.array(cv2.imread(imagePath[i])) for i in range(len(imagePath))] )
print x_data.shape
Run Code Online (Sandbox Code Playgroud)
这给了我: (1000, 64, 64, 3)
如果我这样做:
pixels = x_data.flatten()
print pixels.shape
Run Code Online (Sandbox Code Playgroud)
我明白了: (12288000,)
但是,我需要一个具有以下尺寸的数组: (1000, 12288)
我怎样才能做到这一点?
我想根据示例上传我的文件需要一个最小的 Django 文件上传示例,但是我想不将文件存储在本地,而是使用 FTP 存储在另一台服务器上。
我一直在尝试让这段代码工作,这看起来很简单,但是 ImportError: No module named FTPStorage当我运行时我一直在 python manage.py runserver
我查看了多个存储库并搜索了该站点,但无济于事。我想这是一个相当简单的任务,但我似乎无法让它工作。
谢谢。
文件夹结构
设置.py
"""
Django settings for myproject project.
Generated by 'django-admin startproject' using Django 1.8.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = …Run Code Online (Sandbox Code Playgroud) 我有一个数据框,我想按组 ID 将其拆分为训练集和测试集。以下代码对随机行进行采样并将它们放入训练和测试 df 中:
samp <- sample(nrow(df), 0.7 * nrow(df))
train <- df[samp, ]
test <- df[-samp, ]
Run Code Online (Sandbox Code Playgroud)
但是,我想将我的 ID 组合在一起。
示例输入 df:
my_dat <- data.frame(ID=as.factor(rep(1:3, each = 3)), Var=sample(1:100, 9))
ID Var
1 17
1 26
1 100
2 9
2 41
2 49
3 36
3 18
3 5
Run Code Online (Sandbox Code Playgroud)
和所需的输出:
火车:
ID Var
1 17
1 26
1 100
3 36
3 18
3 5
Run Code Online (Sandbox Code Playgroud)
测试:
ID Var
2 9
2 41
2 49
Run Code Online (Sandbox Code Playgroud) 我有一个数据集,我想在其中过滤不同组中的行。
给定这个数据框:
group = as.factor(c(1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3))
fruit = as.factor(c("apples", "apples", "apples", "oranges",
"oranges", "apples", "oranges",
"bananas", "bananas", "oranges", "bananas"))
hit = c(1, 0, 1, 1,
0, 1, 1,
1, 0, 0, 1)
dt = data.frame(group, fruit, hit)
dt
group fruit hit
1 apples 1
1 apples 0
1 apples 1
1 oranges 1
2 oranges 0
2 apples 1
2 oranges 1
3 bananas 1
3 bananas 0
3 oranges 0 …Run Code Online (Sandbox Code Playgroud) 我有一个嵌套列表,并希望用数据帧的行值替换每个子列表的第二项.这是我的数据框和列表:
import pandas as pd
mydata = [{'id' : '12'},
{'id' : '34'},
{'id' : '56'},
{'id' : '78'},]
df = pd.DataFrame(mydata)
L1 = [ ['elephant',0], ['zebra',1], ['lion',2], ['giraffe',3] ]
Run Code Online (Sandbox Code Playgroud)
期望的结果是: [ ['elephant',12], ['zebra',34], ['lion',56], ['giraffe',78] ]
这是我的代码:
for i in L1:
for j, row in df.iterrows():
i[1] = df["id"][j]
Run Code Online (Sandbox Code Playgroud)
哪个输出: [['elephant', '78'], ['zebra', '78'], ['lion', '78'], ['giraffe','78']]
我有以下字符串,我想删除所有EUR的实例
var str = "200.00 EUR, 33.33 EUR, 100.95 EUR, 300 EUR";
Run Code Online (Sandbox Code Playgroud)
所以输出是:
var str ="200.00,33.33,100.95,300";
我试过了
var res = str.replace("EUR", "");
Run Code Online (Sandbox Code Playgroud)
但这只能取消欧元一次.