我正在处理包含坐标x,y,z的文本文件
1 128 1298039
123388 0 2
....
Run Code Online (Sandbox Code Playgroud)
每行使用分为3个项目
words = line.split()
Run Code Online (Sandbox Code Playgroud)
在处理数据之后,我需要在另一个txt文件中写回坐标,以便每列中的项目对齐(以及输入文件).每一行都由坐标组成
line_new = words[0] + ' ' + words[1] + ' ' words[2].
Run Code Online (Sandbox Code Playgroud)
std::setw()在C++中是否有类似的操纵器允许设置宽度和对齐?
对不起有点初学者的问题.有矢量和矢量对
typedef std::vector <int> TItems;
typedef std::vector < std::pair <int, int> > TPairs;
Run Code Online (Sandbox Code Playgroud)
有没有办法在一步中将对中的所有第一项转换为另一个向量
int main ()
{
TItems items;
TPairs pairs;
pairs.push_back (std::make_pair(1,3));
pairs.push_back (std::make_pair(5,7));
std::transform( items.begin(), items.end(), items.begin(), comp ( &pairs ) );
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如何设计仿函数?
class comp
{
private:
TPairs *pairs;
public:
comp ( TPairs *pairs_ ) : pairs ( pairs_) { }
unsigned int operator () ( const unsigned int index ) const
{
return (*pairs)[index].second != pairs->end(); //Bad idea
}
};
Run Code Online (Sandbox Code Playgroud)
也许有一些没有lambda表达式和循环的用户友好方法.谢谢你的帮助.
如何测试点P = [xp,yp]是否在由中心C = [x,y],a,b和phi(旋转角度)给出的某个旋转椭圆的内部/外部?
此时我正在使用以下解决方案:旋转椭圆并用角度-phi指向,然后对点的位置和"非旋转"椭圆进行常见测试.
但是有很多测试点(数千),我觉得这个解决方案很慢.有没有直接和更有效的方法来获得旋转椭圆和点的位置?
我不需要代码而是算法.谢谢你的帮助.
操作A\B的结果是什么,其中A(1,m)和B(1,m)?
在手册中写道:
A\B returns a least-squares solution to the system of equations A*x= B.
Run Code Online (Sandbox Code Playgroud)
所以它意味着x = inv(A'*A)*A'*B?但是,矩阵A'*A是单数的......
让我们假设:
A=[1 2 3]
B=[6 7 6]
A\B
0 0 0
0 0 0
2.0000 2.3333 2.0000
Run Code Online (Sandbox Code Playgroud)
如果使用MLS:
C = inv (A'*A) singular matrix
C = pinv(A'*A)
0.0051 0.0102 0.0153
0.0102 0.0204 0.0306
0.0153 0.0306 0.0459
D= C*A'*B
0.4286 0.5000 0.4286
0.8571 1.0000 0.8571
1.2857 1.5000 1.2857
Run Code Online (Sandbox Code Playgroud)
所以结果A\B和inv(A'*A)*A'*B是不同的......
存在包含内部结构TIn的结构TOut:
template <typename T>
struct TOut
{
struct TIn
{
bool b;
};
TIn in;
T t;
};
Run Code Online (Sandbox Code Playgroud)
如何正确传递TIn作为某种方法的形式参数?
class Test
{
public:
template <typename T>
static void test ( const TOut<T>::TIn &i) {} //Error
};
int main()
{
TOut <double> o;
Test::test(o.in);
}
Run Code Online (Sandbox Code Playgroud)
该程序编译时出现以下错误:
Error 4 error C2998: 'int test' : cannot be a template definition
Run Code Online (Sandbox Code Playgroud) 假设以下具有2个类型T,U的泛型类
public class Pair<T, U> implements Comparable<T, U> { //Error 1
private final T first;
private final U second;
public Pair(T first_, U second_) {
first = first_;
second = second_;}
public T getFirst() { return first; }
public U getSecond() { return second; }
}
Run Code Online (Sandbox Code Playgroud)
及其项目清单
List<Pair<Integer, Integer>> = new ArrayList<>()
Run Code Online (Sandbox Code Playgroud)
需要根据first / second属性进行排序。不幸的是,类定义包含一些问题,出现以下错误:
Error 1: wrong number of type arguments
Run Code Online (Sandbox Code Playgroud)
如何设计比较器类?此代码可能是完全错误的
public class SortBySecond implements Comparable <Pair <T, U>> {
public int compare(final Pair<T, U> p1, final Pair<T, …Run Code Online (Sandbox Code Playgroud) 有两个int的未分类向量和对int,int的向量
std::vector <int> v1;
std::vector <std::pair<int, float> > v2;
Run Code Online (Sandbox Code Playgroud)
包含数百万件物品.
如何尽可能快地从v1中删除这些v2.first独有的项目(即不包含在v2.first中)?
例:
v1: 5 3 2 4 7 8
v2: {2,8} {7,10} {5,0} {8,9}
----------------------------
v1: 3 4
Run Code Online (Sandbox Code Playgroud) 有结构TA
template <typename T>
struct TA
{
typedef std::vector <T> Type;
};
Run Code Online (Sandbox Code Playgroud)
和test()函数具有类型TA的默认参数.
template <typename T>
void test ( typename TA<T>::Type a1,
typename TA<T>::Type a2 = typename TA<T>::Type(a1.size()) )
{}
Run Code Online (Sandbox Code Playgroud)
是否可以在默认参数a2定义中使用a1.size()?
int main()
{
TA <double> ::Type a1;
test<double>(a1);
}
Run Code Online (Sandbox Code Playgroud) 对于相同类型的集合,有2个迭代器:
typename TFunction <T>::Type ::const_iterator i1 = f1.begin();
typename TFunction <T>::Type ::const_iterator i2 = f2.begin();
Run Code Online (Sandbox Code Playgroud)
在几个步骤之后,i1指向具有index = index1的f1的一些元素(可能不知道).我需要将第二个迭代器i2设置为具有与index1相同索引的f2元素...
这可以在没有将i1转换为索引的情况下完成吗?
有没有办法如何使用std::rotate列表
std::list<int> v = { 0,7, 1,2 };
Run Code Online (Sandbox Code Playgroud)
因为这些左/右旋转
std::rotate(v.begin(), v.begin() + 1, v.end());
std::rotate(v.rbegin(), v.rbegin() + 1, v.rend());
Run Code Online (Sandbox Code Playgroud)
为矢量工作?
std::vector<int> v = { 0, 7, 1, 2 };
Run Code Online (Sandbox Code Playgroud)
一种可能的方法是将列表复制到向量
std::vector<int> u{ std::begin(v), std::end(v) };
Run Code Online (Sandbox Code Playgroud)
反之亦然,但我发现它太"冗长"......直接轮换列表会导致以下错误:
Error C2672 'std::rotate': no matching overloaded function found
Error C2676 binary '+': std::_List_iterator<std::_List_val<std::_List_simple_types<_Ty>>>' does not define this operator or a conversion to a type acceptable to the predefined operator
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
c++ ×6
vector ×3
algorithm ×2
templates ×2
alignment ×1
comparator ×1
default ×1
definition ×1
ellipse ×1
functor ×1
generics ×1
iterator ×1
java ×1
list ×1
matlab ×1
operators ×1
parameters ×1
point ×1
position ×1
python ×1
rotation ×1
set ×1
std-pair ×1
struct ×1
testing ×1
transform ×1
unique ×1