我知道如何在R中这样做.但是,pandas中是否有任何函数将数据帧转换为包含两个方面共同计数的nxn共生矩阵.
例如矩阵df:
import pandas as pd
df = pd.DataFrame({'TFD' : ['AA', 'SL', 'BB', 'D0', 'Dk', 'FF'],
'Snack' : ['1', '0', '1', '1', '0', '0'],
'Trans' : ['1', '1', '1', '0', '0', '1'],
'Dop' : ['1', '0', '1', '0', '1', '1']}).set_index('TFD')
print df
>>>
Dop Snack Trans
TFD
AA 1 1 1
SL 0 0 1
BB 1 1 1
D0 0 1 0
Dk 1 0 0
FF 1 0 1
[6 rows x 3 columns]
Run Code Online (Sandbox Code Playgroud)
会屈服:
Dop …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Windows 10上的GUI 构建FIATCMake.
CMake Error at CMakeLists.txt:3 (project):
Failed to run MSBuild command:
MSBuild.exe
to get the value of VCTargetsPath:
Configuring incomplete, errors occurred!
Run Code Online (Sandbox Code Playgroud)
我配置CMake使用Visual Studio 15 2017编译器.
我怎样才能解决这个问题?
如果需要,这是CMakeLists.txt文件
cmake_minimum_required(VERSION 3.2)
include(CheckCXXCompilerFlag)
project(FIAT CXX)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if(CHECK_CXX_COMPILER_USED1)
# Using Visual Studio C++
elseif("${CMAKE_CXX_COMPILER_ID}x" STREQUAL "MSVCx")
# Using Intel C++
elseif("${CMAKE_CXX_COMPILER_ID}x" STREQUAL "Intelx")
else(CHECK_CXX_COMPILER_USED1)
# GCC or Clang
# At least C++11
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
CHECK_CXX_COMPILER_FLAG("-std=c++1z" COMPILER_SUPPORTS_CXX1Z)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
CHECK_CXX_COMPILER_FLAG("-std=c++1y" COMPILER_SUPPORTS_CXX1Y)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX17) …Run Code Online (Sandbox Code Playgroud) 当我尝试使用keras'加载权重时,model.load_weights I get OSError: Unable to open file (Truncated file: eof = 41091072)这是完整的错误跟踪:
model.load_weights(get_file(fname, "E:/Work/Practical\ Deep\ Learning\ Course/my\ notebooks/lesson1/vgg16.h5", cache_subdir='models'))
141
142
C:\....\Anaconda3\envs\tensorflow\lib\site-packages\keras\engine\topology.py in load_weights(self, filepath, by_name)
2700 """
2701 import h5py
-> 2702 f = h5py.File(filepath, mode='r')
2703 if 'layer_names' not in f.attrs and 'model_weights' in f:
2704 f = f['model_weights']
C:\....\Anaconda3\envs\tensorflow\lib\site-packages\h5py\_hl\files.py in __init__(self, name, mode, driver, libver, userblock_size, swmr, **kwds)
269
270 fapl = make_fapl(driver, libver, **kwds)
--> 271 fid = make_fid(name, mode, userblock_size, …Run Code Online (Sandbox Code Playgroud) 我正在尝试配置theano以gpu在我的 Windows 机器上使用。我已经设置.theanorc为使用,device= gpu但是当我运行一些应该使用 gpu 的代码时,我收到以下错误:
Can not use cuDNN on context None: cannot compile with cuDNN. We got this error:
c:\users\...\appdata\local\temp\try_flags_pt24sj.c:4:19: fatal error: cudnn.h: No such file or directory
compilation terminated.
Mapped name None to device cuda0: GeForce 840M (0000:03:00.0)
Run Code Online (Sandbox Code Playgroud)
我检查了我的CUDA_PATH=C:\Program Files\NVIDIA\v8.0GPU Computing Toolkit\CUDA 以查看 cudnn.h 是否存在,并且我在C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include
在初始化常量数据成员时,以下四种不同的语法是否做同样的事情,例如,在C++ 11中是int类型?如果没有,有什么区别?
{
const int a = 5; //usual initialization, "=" is not assignment operator here it is an initialization operator.
}
{
const int a(5); //calling the constructor function directly
}
{
const int a = {5}; //similar to initializing an array
}
{
const int a{5}; //it should work, but visual studio does not recognizing it
}
Run Code Online (Sandbox Code Playgroud)
为什么第四个不被Visual Studio识别为有效语句?
我试图通过运行以下代码将某些文件从 S3 下载到本地计算机:
import subprocess, os
ec2_root = '/home/'
s3_root_path = "S3://bucket-name/"
s3_download_command = ["aws", "s3", "cp", os.path.join(s3_root_path, 'my_video.mp4'), os.path.join(local_root)]
p = subprocess.Popen(s3_download_command)
p.communicate()
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
usage: aws s3 cp <LocalPath> <S3Uri> or <S3Uri> <LocalPath> or <S3Uri> <S3Uri> Error: Invalid argument type
我正在尝试连接两个文件,第一个包含音频和视频,而第二个仅包含视频。我使用以下ffmpeg命令:
ffmpeg_command = ["ffmpeg", "-f", "concat", "-safe", "0", "-i", "clips_to_join.txt", "-vcodec", "copy", "-acodec", "copy", output_file_path] # output_filename = ch0X-start_time-end_time
p = subprocess.Popen(ffmpeg_command)
p.communicate()
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
libavutil 54. 31.100 / 54. 31.100
libavcodec 56. 60.100 / 56. 60.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 40.101 / 5. 40.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
libpostproc 53. 3.100 / …Run Code Online (Sandbox Code Playgroud) 我有一个控制器方法,我想用它来向视图发送列表和小数,而不使用模型。我怎样才能这样做呢?这是我从控制器对视图的调用:
decimal totBalance = 10.0M;
return View(query.ToList(), totBalance);
Run Code Online (Sandbox Code Playgroud) 我有一个熊猫表,格式如下:
anger_metric metric_name angle_value
0 71.0991 roll 14.6832
1 71.0991 yaw 0.7009
2 71.0991 pitch 22.5075
3 90.1341 roll 4.8566
4 90.1341 yaw 6.4458
5 90.1341 pitch -10.1930
Run Code Online (Sandbox Code Playgroud)
我需要为此创建一个视图,使其像这样:
anger_metric roll yaw pitch
0 71.0991 14.6832 0.7009 22.5075
1 90.1341 4.8566 6.4458 -10.1930
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
df2= results.pivot(index='anger_metric', columns='metric_name', values='angle_value')
# results is the pnadas table/list
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
ValueError: Index contains duplicate entries, cannot reshape
Run Code Online (Sandbox Code Playgroud)
如何处理呢?
我有一个udp使用python 的服务器,该服务器以原始格式(字节数组)连续接收来自客户端的语音数据包。如何在服务器端实时播放声音?有推荐的库或方法吗?
如果需要,这是我非常简单的服务器代码(我对此表示怀疑)
import socket
UDP_IP = "192.168.1.105"
UDP_PORT = 5005
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
#what to do to stream the incoming voice packets?
Run Code Online (Sandbox Code Playgroud) 如何从内部作用域访问全局变量,给定以下代码示例,如何从主函数和最内部作用域访问全局字符串 X,一旦我们退出它,最内部作用域也是可访问的主要范围还是其他范围?
#include <iostream>
#include <string>
std::string x = "global";
int counter = 1;
int main()
{
std::cout <<counter ++ << " " << x << std::endl;
std::string x = "main scope";
std::cout <<counter ++ << " " << x << std::endl;
{
std::cout <<counter ++ << " " << x << std::endl;
std::string x = "inner scope";
std::cout <<counter ++ << " " << x << std::endl;
}
std::cout <<counter++ << " " << x << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
目前的 …
pop()函数有什么问题,为什么它不能正常工作?
class stack{
int *p, *Cursor;
int size ;
public:
stack(int sz) {Cursor = p = new int[size=sz+1];} //consider the stack empty when its size is 1
~stack() {delete[] p;} //Cursor and P will be destroyed when the program finishes
void push(int x) {Cursor+=1; *Cursor=x; size++;}
int pop() {if(Cursor == p) return -1; int temp = *Cursor; Cursor--; size--; return (temp);}
bool isEmpty(){return(Cursor == p);}
bool isFull(){return(Cursor == p+size);}
};
Run Code Online (Sandbox Code Playgroud)
这是我的测试:
stack A(3);
std::cout<<"Empty: "<<A.isEmpty()<<std::endl;
std::cout<<"Full: "<<A.isFull()<<std::endl;
A.push(10);
A.push(20);
A.push(30); …Run Code Online (Sandbox Code Playgroud) python ×5
c++ ×3
c++11 ×2
pandas ×2
amazon-s3 ×1
asp.net-mvc ×1
audio ×1
c# ×1
cmake ×1
cmake-gui ×1
codec ×1
cudnn ×1
dataframe ×1
duplicates ×1
ffmpeg ×1
h5py ×1
keras ×1
msbuild ×1
pivot ×1
scopes ×1
stack ×1
statistics ×1
syntax ×1
theano ×1
theano-cuda ×1
video ×1
voice ×1
voip ×1
windows ×1