RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-198294

alex-rudenkiy's questions

Martin Hope
alex-rudenkiy
Asked: 2020-10-27 03:10:55 +0000 UTC

为什么从 DLL 调用不安全的函数会使一切崩溃

  • 0

请告诉我调用函数时我做错了什么?:

static class NativeMethods
{
    [DllImport("kernel32.dll")]
    public static extern IntPtr LoadLibrary(string dllToLoad);

    [DllImport("kernel32.dll")]
    public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);

    [DllImport("kernel32.dll")]
    public static extern bool FreeLibrary(IntPtr hModule);
}

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate IntPtr CreateSemaphore(uint dwDesiredAccess, long lInitialCount, long lMaximumCount, string lpName);


IntPtr pDll = NativeMethods.LoadLibrary(@"kernel32.dll");
IntPtr pAddressOfFunctionToCall = NativeMethods.GetProcAddress(pDll, "CreateSemaphoreA");
CreateSemaphore createSemaphore = (CreateSemaphore)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(CreateSemaphore));
IntPtr theResult = createSemaphore(0,2,2,"qwerty");

我也尝试使用 PInvoke 来做:

[DllImport("kernel32.dll", SetLastError = true)]
public static extern HANDLE CreateSemaphore(uint dwDesiredAccess, long lInitialCount, long lMaximumCount, string lpName);

IntPtr result = winapi.CreateSemaphore(0,0,3,"qwerty");

错误是可以更改内存等,但是我运行 CreateMutex (public static extern IntPtr CreateMutex(IntPtr lpMutexAttributes, bool bInitialOwner, string lpName)) ,一切都很好((((

升级版:

        [UnmanagedFunctionPointer(CallingConvention.StdCall,CharSet = CharSet.Ansi)]
        private delegate IntPtr CreateSemaphore(IntPtr dwDesiredAccess, long lInitialCount, long lMaximumCount, string lpName);

        IntPtr pDll = NativeMethods.LoadLibrary(@"kernel32.dll");
        IntPtr pAddressOfFunctionToCall = NativeMethods.GetProcAddress(pDll, "CreateSemaphoreA");
        CreateSemaphore createSemaphore = (CreateSemaphore)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(CreateSemaphore));
        IntPtr theResult = createSemaphore(new IntPtr(),2,2,"qwerty");
c#
  • 1 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-05-12 01:55:56 +0000 UTC

真的是遗传吗?

  • 0

可以这样继承吗?我只是得到错误:

class Human:public Node<Human>; //Здесь unknown template name 'Node' и expected '{' after base class list

template <class T>
class Node{
private:
    T data;
    QList<Node<T>*> childs;
    QList<Node<T>*> parents;

public:
    Node(){
        qDebug( "Node construct" );
    };
    Node(T* newdata){
        qDebug( "Node construct" );
        data = *newdata;
    };
    T get_data(){ return data; }
    void set_data(T new_data){data=new_data;}
    void add_child(T* child){ childs.push_back(new Node(child));}
    void add_parent(T* parent){parents.push_back(new Node(parent));}

    QList<Node<T>*>* get_childs(){return &childs;}
    QList<Node<T>*>* get_parents(){return &parents;}
    ~Node(){

    }
};

class Human:public Node<Human>{ // А здесь redefinition of 'Human'
private:
    int id;
    Node<Human> *node = new Node<Human>();
    Photo avatar;
    QString firstname;
    QString lastname;
    QString description;
    Gallery gallery;
    QList<Event*> events;
public:
    Human(){}
    Human(QString firstname,QString lastname,QString description):firstname(firstname),lastname(lastname),description(description){};
    QString get_firstname();
    QString get_lastname();
    Photo get_avatar();
    QList<Event *> get_events();
    Gallery get_gallery();
    void change_firstname(QString);
    void change_lastname(QString);
    void change_description(QString);
    void add_child(Human*);
    void add_parent(Human*);
    QList<Node<Human> *> *get_childs();
    QList<Node<Human> *> *get_parents();
};
c++
  • 1 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-04-17 20:00:32 +0000 UTC

模板的问题

  • 2

请告诉我为什么我不能用模板实现接口?

队列.h

#ifndef UNTITLED104_QUEUE_H
#define UNTITLED104_QUEUE_H

#include <vector>
#include <cstdio>

using namespace std;

template <typename T>
class Node{
private:
    T value;
public:
    Node *next_node, *back_node;

    Node():next_node(NULL),back_node(NULL){};
    Node(T new_value):value(new_value),next_node(NULL),back_node(NULL){};

    T getValue();
    void setValue(T new_value);
    void deleteNode();
    Node* getNext();
    Node* getBack();
};

template <typename T>
class Queue{
private:
    Node<T>* firstNode=NULL;
    unsigned size=0;
public:
    Queue(T value);
    Node<T>* getFirst();
    Node<T>* getNode(int position);
    unsigned int getSize();
    Node<T>* insert_after(int position, T value);
};

#endif //UNTITLED104_QUEUE_H

队列.cpp

#include "Queue.h"

template<typename T>
T Node<T>::getValue() {
    return nullptr;
}

template<typename T>
void Node<T>::setValue(T new_value) {
}

template<typename T>
void Node<T>::deleteNode() {
}

template<typename T>
Node *Node<T>::getNext() {
    return nullptr;
}

template<typename T>
Node *Node<T>::getBack() {
    return nullptr;
}




template<typename T>
Queue<T>::Queue(T value) {
}

template<typename T>
Node<T> *Queue<T>::getFirst() {
    return nullptr;
}

template<typename T>
Node<T> *Queue<T>::getNode(int position) {
    return nullptr;
}

template<typename T>
unsigned int Queue<T>::getSize() {
    return 0;
}

template<typename T>
Node<T> *Queue<T>::insert_after(int position, T value) {
    return nullptr;
}

错误:

C:\Users\Alex\CLionProjects\untitled104\Queue.cpp:21:1: error: invalid use of template-name 'Node' without an argument list
 Node *Node<T>::getNext() {
 ^
C:\Users\Alex\CLionProjects\untitled104\Queue.cpp:26:1: error: invalid use of template-name 'Node' without an argument list
 Node *Node<T>::getBack() {
 ^
c++
  • 3 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-04-13 00:39:55 +0000 UTC

异常堆栈,如何处理?

  • 0

棘手的问题,谁知道是否可以在 func3 中捕获 MyException1?

#include <iostream>

class MyException1: public std::exception {
public:
    virtual const char* what() const throw()
    {
        return "Error1";
    }
};

class MyException21: public std::exception {
public:
    virtual const char* what() const throw()
    {
        return "Error21";
    }
};

class MyException22: public std::exception {
public:
    virtual const char* what() const throw()
    {
        return "Error22";
    }
};

void func1(){
    throw MyException1();
}

void func2(){
    throw MyException1();
}

void func12(){
    try {
        func1();
    }catch (MyException1& exception1){
        throw MyException21();
    }
}

void func22(){
    try {
        func2();
    }catch (MyException1& exception1){
        throw MyException22();
    }
}

void func3(){
    try {
        func12();
        func22();
    }catch (MyException1& exception1){
        std::cout<<exception1.what(); // Вот здесь должно выводиться "Error1"
    }catch (MyException21& exception21){
        std::cout<<exception21.what(); // Но выводится "Error21", что логично, но как вот весь стек ошибок перехватить, т.е. MyException1 тоже?
    }
}

int main() {
    func3();

    return 0;
}
c++
  • 2 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-10-20 01:52:08 +0000 UTC

不是固定数量的输出

  • 1

请告诉我如何在 Keras 上的 NS 中实现输出结果的动态数量。好吧,例如图像中物体的识别,原则上,国民议会可以强制搜索一个没有问题的物体(可能),因此输出包含我们识别的左上角和右上角坐标对象,但是当我们有多个对象时该怎么办?o_o

нейронные-сети
  • 1 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-10-01 00:19:08 +0000 UTC

动态添加Node时,没有样式

  • 0

请告诉我,当动态添加节点时,它上面没有样式,更准确地说,它们在代码检查器中,但不在样式检查器和屏幕本身中时该怎么办?

var newNode='<div class="list col-sm" style="border: black;border-style: dashed;border-width: 1px;background-color: #00000012;"> My DIV </div>';
var parser = new DOMParser();
doc = parser.parseFromString(newNode, "text/xml").documentElement;

var stack = document.getElementById('lol');
//stack.insertAdjacentElement('beforeEnd', doc);
stack.appendChild(doc);

我试图强制重绘,但唉:

    function Force(){
        var element=$('#myfrm')
        var disp = element[0].style.display;
        element[0].style.display = 'none';
        var trick = element[0].offsetHeight;
        element[0].style.display = disp;
    }
javascript
  • 1 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-09-22 02:41:11 +0000 UTC

为什么字符数组字符指针会改变?

  • 0

告诉我为什么会发生这种异常,或者更确切地说,指向字符数组的第二个字符的指针由于某种原因发生了变化?

00000000000A2390 00000000000A22D0
00000000000A2390 00000000000A2391
void InitStr(string1 *s, unsigned n){
    *(s) = malloc((n+4) * sizeof(char));
    *(s[0]) = (char)CHAR_MIN+(char)n;
    *(s[1]) = (char)CHAR_MIN;
    printf("%p %p\n",s[0],s[1]);
}

unsigned Length(string1 s){
    printf("%p %p\n",&s[0],&s[1]);
}
c
  • 1 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-09-19 02:45:06 +0000 UTC

为什么我的双精度显示不正确?

  • 1

请告诉我我的错误在哪里,为什么我不能(完全)以二进制格式打印双格式的数量?

例如,20.18

0 10000000011 0100001011100001010001111010111000010100011110101110 

位数对应IEEE 754标准,第一位(符号)对应开头,这是肯定的,因为我试过 -20.18,结果是 1,但其余的根本不收敛:(


这是代码本身:

void PrintByte(char a) //выводит на экран монитора двоичное представление переменной а типа unsigned char.
{
    int i;
    char mask = 1 << 7;
    for (i = 0; i < 8; i++) {
        printf("%i", a & mask ? 1 : 0);
        a <<= 1;
    }
}

void PrintVar(void *a, int size) //выводит на экран монитора двоичное представление переменной а произвольного типа размером size байт
{
    int i;
    char *p = a;
    for (i = size - 1; i >= 0; i--) PrintByte(*(p + i));
    puts("");
}

int main() {
    double d = 20.18;
    PrintVar(&d, sizeof(double));
    return 0;
}
c
  • 1 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-09-17 05:47:53 +0000 UTC

model.predict 总是返回相同的值

  • 1

告诉我为什么 predict 在不同的输入图像上不断返回相同的值,前提是神经网络经过某种训练?

model.predict(np.array([images[20]])) Out[45]: array([[0.48986772, 0.25879842]], dtype=float32) model.predict(np.array([images[17]]) ) Out[46]: array([[0.48986772,0.25879842]], dtype=float32)

images = load_data(data_dir)
images = np.asarray(images, dtype=np.float32)
images /= 255
answers = np.asarray(predicts, dtype=np.float32)
maxval = np.amax(answers)
answers /= maxval
images = images.reshape(images.shape[0], 80, 60, 1)

model=Sequential()

model.add(Conv2D(32, (3, 3), padding='same', activation='relu', input_shape=(80, 60,1)))
model.add(Conv2D(32, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))

model.add(Conv2D(64, (3, 3), padding='same', activation='relu'))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))

model.add(Conv2D(64, (3, 3), padding='same', activation='relu'))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))

model.add(Flatten())
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(256, activation='softmax'))
model.add(Dropout(0.25))
model.add(Dense(256, activation='relu'))
model.add(Dropout(0.25))

#model.add(Dense(2, activation='softmax'))

model.add(Dense(2))

model.summary()

batch_size = 256
epochs = 15
model.compile(optimizer=Adam(lr=0.05), loss='mean_squared_error', metrics=['accuracy'])

history = model.fit(images, answers, batch_size=batch_size, epochs=epochs, verbose=1, validation_split=0.1)

在此处输入图像描述 在此处输入图像描述 在此处输入图像描述


升级版:

好吧,看,这是一个“通用”算法,它是为加载分类数据量身定制的)

def load_data(data_dir):

    directories = [d for d in os.listdir(data_dir)
                   if os.path.isdir(os.path.join(data_dir, d))]

    labels = []
    images = []

    category = 0
    for d in directories:
        label_dir = os.path.join(data_dir, d)
        file_names = [os.path.join(label_dir, f)
                      for f in os.listdir(label_dir)
                      if f.endswith(".jpg")]

        for f in file_names:
            img = cv2.imread(f, cv2.IMREAD_GRAYSCALE)
            img = cv2.resize(img, (80, 60))
            #plt.figure()
            #plt.imshow(img)
            images.append(img)
            labels.append(category)

        category += 1

    return images, labels

升级版:

def load_data(data_dir):
    images = []
    file_names = [os.path.join(data_dir, f)
        for f in os.listdir(data_dir)
        if f.endswith(".jpg")]

    for f in file_names:
        img = cv2.imread(f, cv2.IMREAD_GRAYSCALE)
        img = cv2.resize(img, (80, 60))
        images.append(img)
    return images

更新:

Epoch 00024: loss did not improve from 148.46680
Epoch 00024: early stopping
392.36053

Y_test
Out[15]: 
array([[ 754.,   85.],
       [ 214.,  528.],
       [ 697.,  218.],
       [ 830.,  365.],
       [ 299.,  145.],
       [1314.,  222.],
       [ 302.,  439.],
       [1449.,  738.],
       [ 856.,  406.],
       [ 759.,  584.],
       [ 336.,  427.],
       [ 285.,  754.],
       [ 373.,  577.]], dtype=float32)

Y_pred
Out[16]: 
array([[1200.4126 ,  298.62018],
       [1210.8347 ,  338.11783],
       [1216.1664 ,  304.6189 ],
       [1329.8218 ,  368.26013],
       [1166.9604 ,  292.44904],
       [1309.2661 ,  352.29883],
       [1195.6471 ,  318.59082],
       [1449.1544 ,  401.64136],
       [1292.0201 ,  333.70294],
       [1320.844  ,  363.69574],
       [1190.2806 ,  319.49582],
       [1272.7736 ,  377.27615],
       [1275.2628 ,  351.26425]], dtype=float32)
python
  • 1 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-08-26 02:57:57 +0000 UTC

为什么维度越来越大?

  • 2

棘手的问题,为什么从 2d (x,y) 开始的数据的维度在每次卷积后都会增加? 在此处输入图像描述

更新:

在此处输入图像描述

首先键入每个过滤器,这大致是一个小特征(鼻子的边界,耳朵的边界),然后将其与其他一般过滤器特征泛化为一般特征(鼻子,耳朵等)

нейронные-сети
  • 1 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-08-22 00:53:18 +0000 UTC

使用勾股定理训练神经网络

  • 4

我想教神经网络勾股定理。一切似乎都正确完成,标准化数据,模型正确,但不清楚错误是什么..

import numpy as np

from keras.models import Sequential
from keras.layers.core import Dense, Activation
from keras.utils import np_utils

np.random.seed()

NB_EPOCH = 500
VERBOSE = 1

X_in = [[ 0 , 44 ], [ 0 , 18 ], [ 38 , 0 ], [ 48 , 14 ], [ 0 , 36 ], [ 14 , 0 ], [ 34 , 0 ], [ 0 , 0 ], [ 0 , 38 ], [ 32 , 0 ], [ 28 , 0 ], [ 36 , 0 ], [ 20 , 48 ], [ 0 , 6 ], [ 0 , 20 ], [ 0 , 42 ], [ 0 , 8 ], [ 24 , 32 ], [ 4 , 0 ], [ 6 , 8 ], [ 24 , 10 ], [ 0 , 22 ], [ 16 , 12 ], [ 30 , 40 ], [ 0 , 32 ], [ 0 , 32 ], [ 16 , 0 ], [ 48 , 20 ], [ 0 , 8 ], [ 32 , 0 ], [ 0 , 46 ], [ 0 , 22 ], [ 0 , 8 ], [ 10 , 24 ], [ 0 , 36 ], [ 14 , 0 ], [ 0 , 22 ], [ 42 , 0 ], [ 16 , 12 ], [ 40 , 30 ], [ 44 , 0 ], [ 40 , 0 ], [ 34 , 0 ], [ 0 , 32 ], [ 40 , 30 ], [ 32 , 0 ], [ 0 , 30 ], [ 24 , 18 ], [ 0 , 26 ], [ 22 , 0 ], [ 0 , 4 ], [ 16 , 0 ], [ 10 , 0 ], [ 0 , 32 ], [ 0 , 42 ], [ 2 , 0 ], [ 0 , 38 ], [ 32 , 24 ], [ 48 , 0 ], [ 20 , 0 ], [ 0 , 18 ], [ 0 , 38 ], [ 14 , 48 ], [ 40 , 42 ], [ 16 , 12 ], [ 26 , 0 ], [ 0 , 20 ], [ 40 , 30 ], [ 16 , 30 ], [ 36 , 48 ], [ 36 , 0 ], [ 18 , 24 ], [ 34 , 0 ], [ 16 , 0 ], [ 0 , 24 ], [ 0 , 24 ], [ 0 , 18 ], [ 38 , 0 ], [ 28 , 0 ], [ 0 , 34 ], [ 0 , 36 ], [ 24 , 32 ], [ 16 , 30 ], [ 40 , 30 ], [ 24 , 0 ], [ 0 , 14 ], [ 8 , 6 ], [ 12 , 0 ], [ 16 , 0 ], [ 16 , 30 ], [ 48 , 14 ], [ 0 , 30 ], [ 38 , 0 ], [ 38 , 0 ], [ 0 , 8 ], [ 36 , 48 ], [ 0 , 32 ], [ 10 , 24 ], [ 46 , 0 ], [ 24 , 10 ], [ 30 , 0 ], [ 0 , 48 ], [ 40 , 0 ], [ 42 , 0 ], [ 32 , 24 ], [ 32 , 0 ], [ 12 , 16 ], [ 0 , 4 ], [ 0 , 28 ], [ 32 , 0 ], [ 40 , 42 ], [ 46 , 0 ], [ 0 , 24 ], [ 30 , 16 ], [ 36 , 48 ], [ 40 , 0 ], [ 24 , 0 ], [ 0 , 22 ], [ 40 , 42 ], [ 10 , 24 ], [ 0 , 16 ], [ 14 , 48 ], [ 22 , 0 ], [ 0 , 22 ], [ 30 , 0 ], [ 0 , 2 ], [ 48 , 20 ], [ 6 , 0 ], [ 6 , 0 ], [ 28 , 0 ], [ 20 , 0 ], [ 0 , 40 ], [ 42 , 0 ], [ 48 , 36 ], [ 14 , 0 ], [ 10 , 24 ], [ 0 , 30 ], [ 48 , 20 ], [ 40 , 30 ], [ 0 , 0 ], [ 42 , 40 ], [ 0 , 48 ], [ 32 , 24 ]]
X_answer = [[44] ,[18] ,[38] ,[50] ,[36] ,[14] ,[34] ,[0] ,[38] ,[32] ,[28] ,[36] ,[52] ,[6] ,[20] ,[42] ,[8] ,[40] ,[4] ,[10] ,[26] ,[22] ,[20] ,[50] ,[32] ,[32] ,[16] ,[52] ,[8] ,[32] ,[46] ,[22] ,[8] ,[26] ,[36] ,[14] ,[22] ,[42] ,[20] ,[50] ,[44] ,[40] ,[34] ,[32] ,[50] ,[32] ,[30] ,[30] ,[26] ,[22] ,[4] ,[16] ,[10] ,[32] ,[42] ,[2] ,[38] ,[40] ,[48] ,[20] ,[18] ,[38] ,[50] ,[58] ,[20] ,[26] ,[20] ,[50] ,[34] ,[60] ,[36] ,[30] ,[34] ,[16] ,[24] ,[24] ,[18] ,[38] ,[28] ,[34] ,[36] ,[40] ,[34] ,[50] ,[24] ,[14] ,[10] ,[12] ,[16] ,[34] ,[50] ,[30] ,[38] ,[38] ,[8] ,[60] ,[32] ,[26] ,[46] ,[26] ,[30] ,[48] ,[40] ,[42] ,[40] ,[32] ,[20] ,[4] ,[28] ,[32] ,[58] ,[46] ,[24] ,[34] ,[60] ,[40] ,[24] ,[22] ,[58] ,[26] ,[16] ,[50] ,[22] ,[22] ,[30] ,[2] ,[52] ,[6] ,[6] ,[28] ,[20] ,[40] ,[42] ,[60] ,[14] ,[26] ,[30] ,[52] ,[50] ,[0] ,[58] ,[48] ,[40]]
X_in = np.asarray(X_in, dtype=np.float32)
X_answer = np.asarray(X_answer, dtype=np.float32)

X_in /= np.amax(X_in)
X_answer /= np.amax(X_answer)

model = Sequential()
model.add(Dense(10, input_dim = 2, activation='relu'))
model.add(Dense(10, activation='relu'))
model.add(Dense(1, activation='softmax'))

model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy'])

history = model.fit(X_in, X_answer, epochs=NB_EPOCH, verbose=VERBOSE)

对于 100 个 epoch,对于 500 个相同的结果:

Epoch 1/100
143/143 [==============================] - 0s 2ms/step - loss: 0.2966 - acc: 0.0280
Epoch 2/100
143/143 [==============================] - 0s 52us/step - loss: 0.2966 - acc: 0.0280
Epoch 3/100
143/143 [==============================] - 0s 52us/step - loss: 0.2966 - acc: 0.0280
Epoch 4/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 5/100
143/143 [==============================] - 0s 52us/step - loss: 0.2966 - acc: 0.0280
Epoch 6/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 7/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 8/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 9/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 10/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 11/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 12/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 13/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 14/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 15/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 16/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 17/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 18/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 19/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 20/100
143/143 [==============================] - 0s 35us/step - loss: 0.2966 - acc: 0.0280
Epoch 21/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 22/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 23/100
143/143 [==============================] - 0s 35us/step - loss: 0.2966 - acc: 0.0280
Epoch 24/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 25/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 26/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 27/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 28/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 29/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 30/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 31/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 32/100
143/143 [==============================] - 0s 52us/step - loss: 0.2966 - acc: 0.0280
Epoch 33/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 34/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 35/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 36/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 37/100
143/143 [==============================] - 0s 49us/step - loss: 0.2966 - acc: 0.0280
Epoch 38/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 39/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 40/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 41/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 42/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 43/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 44/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 45/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 46/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 47/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 48/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 49/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 50/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 51/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 52/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 53/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 54/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 55/100
143/143 [==============================] - 0s 49us/step - loss: 0.2966 - acc: 0.0280
Epoch 56/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 57/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 58/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 59/100
143/143 [==============================] - 0s 35us/step - loss: 0.2966 - acc: 0.0280
Epoch 60/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 61/100
143/143 [==============================] - 0s 35us/step - loss: 0.2966 - acc: 0.0280
Epoch 62/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 63/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 64/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 65/100
143/143 [==============================] - 0s 52us/step - loss: 0.2966 - acc: 0.0280
Epoch 66/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 67/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 68/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 69/100
143/143 [==============================] - 0s 52us/step - loss: 0.2966 - acc: 0.0280
Epoch 70/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 71/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 72/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 73/100
143/143 [==============================] - 0s 39us/step - loss: 0.2966 - acc: 0.0280
Epoch 74/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 75/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 76/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 77/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 78/100
143/143 [==============================] - 0s 49us/step - loss: 0.2966 - acc: 0.0280
Epoch 79/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 80/100
143/143 [==============================] - 0s 49us/step - loss: 0.2966 - acc: 0.0280
Epoch 81/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 82/100
143/143 [==============================] - 0s 35us/step - loss: 0.2966 - acc: 0.0280
Epoch 83/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 84/100
143/143 [==============================] - 0s 35us/step - loss: 0.2966 - acc: 0.0280
Epoch 85/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 86/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 87/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 88/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 89/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 90/100
143/143 [==============================] - 0s 49us/step - loss: 0.2966 - acc: 0.0280
Epoch 91/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 92/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 93/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
Epoch 94/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 95/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 96/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 97/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 98/100
143/143 [==============================] - 0s 45us/step - loss: 0.2966 - acc: 0.0280
Epoch 99/100
143/143 [==============================] - 0s 42us/step - loss: 0.2966 - acc: 0.0280
Epoch 100/100
143/143 [==============================] - 0s 38us/step - loss: 0.2966 - acc: 0.0280
python
  • 2 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-08-13 23:33:31 +0000 UTC

将类向量转换为二进制矩阵的问题 (np_utils.to_categorical)

  • 1

所以我决定做一个神经网络,理论上应该学习逻辑运算 OR(或),但现在我在准备训练示例的答案时遇到了问题

In [1]: from __future__ import print_function
    ...: import numpy as np
    ...: from keras.datasets import mnist
    ...: from keras.models import Sequential
    ...: from keras.layers.core import Dense, Activation
    ...: from keras.optimizers import SGD
    ...: from keras.utils import np_utils
    ...: np.random.seed(1671) # для воспроизводимости результатов
    ...: 
    ...: NB_EPOCH = 20
    ...: BATCH_SIZE = 3
    ...: VERBOSE = 1
    ...: NB_CLASSES = 1 # количество результатов
    ...: OPTIMIZER = SGD() # СГС-оптимизатор
    ...: N_HIDDEN = 64

In [2]: X_in = [[1,0],[1,1],[0,0],[0,1],[1,1],[0,0],[1,1]]
    ...: x_otvet = [1,1,0,1,1,0,1]
    ...: X_in = np.asarray(X_in, dtype=np.float32)
    ...: x_otvet = np.asarray(x_otvet, dtype=np.float32)

In [3]: x_otvet = np_utils.to_categorical(x_otvet, NB_CLASSES)
Traceback (most recent call last):

  File "<ipython-input-12-a268ac2ea14c>", line 1, in <module>
    x_otvet = np_utils.to_categorical(x_otvet, NB_CLASSES)

  File "D:\Users\Alex\Anaconda3\lib\site-packages\keras\utils\np_utils.py", line 31, in to_categorical
    categorical[np.arange(n), y] = 1

IndexError: index 1 is out of bounds for axis 1 with size 1

如果省略np_utils.to_categorical,则会得到以下信息:

In [13]: model = Sequential()
    ...: model.add(Dense(NB_CLASSES, input_shape=(2,)))
    ...: model.add(Activation('softmax'))
    ...: model.summary()
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense_2 (Dense)              (None, 1)                 3         
_________________________________________________________________
activation_2 (Activation)    (None, 1)                 0         
=================================================================
Total params: 3
Trainable params: 3
Non-trainable params: 0
_________________________________________________________________

In [14]: model.compile(loss='categorical_crossentropy',
    ...: optimizer=OPTIMIZER,
    ...: metrics=['accuracy'])

In [15]: history = model.fit(X_in, x_otvet,
    ...: batch_size=BATCH_SIZE, epochs=NB_EPOCH,
    ...: verbose=VERBOSE)
Traceback (most recent call last):

  File "<ipython-input-15-c47f30350ab5>", line 3, in <module>
    verbose=VERBOSE)

  File "D:\Users\Alex\Anaconda3\lib\site-packages\keras\models.py", line 1002, in fit
    validation_steps=validation_steps)

  File "D:\Users\Alex\Anaconda3\lib\site-packages\keras\engine\training.py", line 1630, in fit
    batch_size=batch_size)

  File "D:\Users\Alex\Anaconda3\lib\site-packages\keras\engine\training.py", line 1493, in _standardize_user_data
    self._feed_output_shapes)

  File "D:\Users\Alex\Anaconda3\lib\site-packages\keras\engine\training.py", line 256, in _check_loss_and_target_compatibility
    ' while using as loss `categorical_crossentropy`. '

ValueError: You are passing a target array of shape (7, 1) while using as loss `categorical_crossentropy`. `categorical_crossentropy` expects targets to be binary matrices (1s and 0s) of shape (samples, classes). If your targets are integer classes, you can convert them to the expected format via:
```
from keras.utils import to_categorical
y_binary = to_categorical(y_int)
```
Alternatively, you can use the loss function `sparse_categorical_crossentropy` instead, which does expect integer targets.

PS如果这是一个愚蠢的问题,我很抱歉。

更新:

好吧,总的来说,我有点纠正我的错误,但现在的问题是我无法理解为什么我的 NS 不喜欢输入数据的格式,数组中有两个元素,但他写了一个?(

In [16]: NB_CLASSES = 2

In [18]: x_otvet = np_utils.to_categorical(x_otvet, NB_CLASSES)

In [20]: model = Sequential()
    ...: model.add(Dense(NB_CLASSES, input_shape=(2,)))
    ...: model.add(Activation('softmax'))
    ...: model.summary()
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense_3 (Dense)              (None, 2)                 6         
_________________________________________________________________
activation_3 (Activation)    (None, 2)                 0         
=================================================================
Total params: 6
Trainable params: 6
Non-trainable params: 0
_________________________________________________________________

In [22]: model.compile(loss='categorical_crossentropy', optimizer=OPTIMIZER, metrics=['accuracy'])

In [23]: history = model.fit(X_in, x_otvet, batch_size=BATCH_SIZE, epochs=NB_EPOCH, verbose=VERBOSE)

Epoch 1/20
7/7 [==============================] - 1s 75ms/step - loss: 0.4861 - acc: 0.8571
Epoch 2/20
7/7 [==============================] - 0s 643us/step - loss: 0.4833 - acc: 1.0000
Epoch 3/20
7/7 [==============================] - 0s 572us/step - loss: 0.4784 - acc: 0.7143
Epoch 4/20
7/7 [==============================] - 0s 500us/step - loss: 0.4751 - acc: 0.7143
Epoch 5/20
7/7 [==============================] - 0s 500us/step - loss: 0.4712 - acc: 0.7143
Epoch 6/20
7/7 [==============================] - 0s 572us/step - loss: 0.4680 - acc: 0.7143
Epoch 7/20
7/7 [==============================] - 0s 643us/step - loss: 0.4637 - acc: 0.7143
Epoch 8/20
7/7 [==============================] - 0s 500us/step - loss: 0.4603 - acc: 0.7143
Epoch 9/20
7/7 [==============================] - 0s 500us/step - loss: 0.4556 - acc: 0.7143
Epoch 10/20
7/7 [==============================] - 0s 500us/step - loss: 0.4525 - acc: 0.7143
Epoch 11/20
7/7 [==============================] - 0s 500us/step - loss: 0.4492 - acc: 0.7143
Epoch 12/20
7/7 [==============================] - 0s 500us/step - loss: 0.4457 - acc: 0.7143
Epoch 13/20
7/7 [==============================] - 0s 429us/step - loss: 0.4416 - acc: 0.7143
Epoch 14/20
7/7 [==============================] - 0s 643us/step - loss: 0.4390 - acc: 0.7143
Epoch 15/20
7/7 [==============================] - 0s 500us/step - loss: 0.4367 - acc: 0.7143
Epoch 16/20
7/7 [==============================] - 0s 500us/step - loss: 0.4342 - acc: 0.7143
Epoch 17/20
7/7 [==============================] - 0s 429us/step - loss: 0.4320 - acc: 0.7143
Epoch 18/20
7/7 [==============================] - 0s 500us/step - loss: 0.4290 - acc: 0.7143
Epoch 19/20
7/7 [==============================] - 0s 500us/step - loss: 0.4269 - acc: 0.7143
Epoch 20/20
7/7 [==============================] - 0s 500us/step - loss: 0.4242 - acc: 0.7143

In [25]: answer = model.predict([1,0])
Traceback (most recent call last):

  File "<ipython-input-25-9f7569b0b419>", line 1, in <module>
    answer = model.predict([1,0])

  File "D:\Users\Alex\Anaconda3\lib\site-packages\keras\models.py", line 1064, in predict
    steps=steps)

  File "D:\Users\Alex\Anaconda3\lib\site-packages\keras\engine\training.py", line 1817, in predict
    check_batch_axis=False)

  File "D:\Users\Alex\Anaconda3\lib\site-packages\keras\engine\training.py", line 123, in _standardize_input_data
    str(data_shape))

ValueError: Error when checking : expected dense_3_input to have shape (2,) but got array with shape (1,)

In [26]: answer = model.predict([1,0])
Traceback (most recent call last):

  File "<ipython-input-26-9f7569b0b419>", line 1, in <module>
    answer = model.predict([1,0])

  File "D:\Users\Alex\Anaconda3\lib\site-packages\keras\models.py", line 1064, in predict
    steps=steps)

  File "D:\Users\Alex\Anaconda3\lib\site-packages\keras\engine\training.py", line 1817, in predict
    check_batch_axis=False)

  File "D:\Users\Alex\Anaconda3\lib\site-packages\keras\engine\training.py", line 123, in _standardize_input_data
    str(data_shape))

ValueError: Error when checking : expected dense_3_input to have shape (2,) but got array with shape (1,)
python
  • 1 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-08-13 03:50:38 +0000 UTC

如何在 NN 中正确准备数据序列

  • 2

我有两个与神经网络有关的问题

1 个问题。例如,如何提供参考时间的数据?在这种情况下,我使用以下示例是否正确:

Время (сек.) | Сенсор №1 (кол-во машин в пробке) | Сенсор №2 (кол-во машин в пробке)

Максимальное значение для времени = 604800 (секунд в неделе)
Максимальное кол-во машин в пробке = 100

2 问题。例如,如果数据属于不同类型,该怎么办:

以下是当此类类型出现在一个结构中时的这种情况:

  • 时间(为方便起见,我们再次以秒为单位存储)
  • 参数(普通数,例如测量某种温度)
  • 布尔值TRUE或FALSE
  • 图像(以下形式的归一化向量{0,1,0.1,0.5,0.3, ...})
нейронные-сети
  • 1 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-07-12 17:03:49 +0000 UTC

如何将函数“分配”给变量?

  • 3

您好,如何将函数“分配”给变量:

有一个垫子。特征:int sum(a,b); int sub(a,b); int div(a,b)

有一个代码:

void main(){
   operation = sum;
}

var operation;
int calc(a,b)
{
   ...
   operation(a,b);
   ...
}

PS我知道如何将函数作为参数传递,但这里的情况不同,有必要将函数“分配”给变量。

c#
  • 1 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-06-24 21:00:20 +0000 UTC

为什么数字比较不正确?

  • 0

为什么数字比较不正确?

printf("%i\n",6==1==0); //1, а по идее должно быть 0, так как не равны
printf("%i\n",0==0==0); //0, по идее 1
c
  • 2 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-06-20 21:43:40 +0000 UTC

为什么 DOMParser 不解析 DOM 结构?[关闭]

  • 0
关闭 这个问题是题外话。目前不接受回复。

该问题是由不再复制的问题或错字引起的。虽然类似的问题可能与本网站相关,但该问题的解决方案不太可能帮助未来的访问者。通常可以通过在发布问题之前编写和研究一个最小程序来重现问题来避免此类问题。

4年前关闭。

改进问题

为什么我的 DOMParser 不解析以下相当简单的 DOM 结构?

var newDOM ="<div><strong>Error!</strong> Refresh, Please... </div>",
    parser = new DOMParser(),
    doc = parser.parseFromString(xmlString, "text/xml");

ReferenceError: xmlString 未定义

javascript
  • 2 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-06-14 01:33:52 +0000 UTC

带有记忆模型的任务

  • 3

请解释如何使用内存模型解决此类问题:

  1. COMPACT 内存模型已安装。pd根据描述,变量将占用多少内存float *pd[5];?
  2. 已安装 MEDIUM 内存型号。a根据描述,变量将占用多少内存char *a[5][2];?
  3. 存在已安装的小内存模型int a[10] = {1, 2, 3, 4, 5}, *p = a+2;以下哪个表达式的计算结果为 2?

    1. (int)p - (int)a;
    2. p - a
    3. *p - *a;
    4. (a[1] + *p) / 2
c
  • 1 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-05-12 19:45:04 +0000 UTC

数据非规范化?

  • 0

我有一个关于 NA 的问题,告诉我如何理解程序应该根据输出层的值执行什么操作?

在此处输入图像描述

нейронные-сети
  • 1 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-04-30 17:55:22 +0000 UTC

为什么垃圾会被扔掉

  • 0

为什么显示垃圾,虽然我检查了地址是否正确传输并且我尝试在 main 中显示字符串(T_String. * Pointer)并且一切都正确返回,但在函数中它不正确?

#include <stdio.h>
#include <stdlib.h>
#include <mem.h>

#define MAX_BUFFER 255

typedef struct{
    int *pointer;
    int length;
} T_String;

int equals_len(T_String *a,int n){
    for (int i = 0; i < n-1; ++i) {
        for (int j = i+1; j < n; ++j) {
            if(a[i].length==a[j].length){
                return 1;
            }
        }
    }
    return 0;
}

//сортировка вставками
void InsertionSort(T_String *a,int n)
{
    T_String b;
    int j;

    for (int i = 1; i < n; i++)
    {
        b = a[i];
        j = i - 1;
        while(j >= 0 && a[j].length > b.length)
        {
            a[j+1] = a[j];
            j = j - 1;
        }
        a[j+1] = b;
    }
}

int word_distantion(T_String *a, T_String *b){
    int d=0;

    for (int i = 0; i < a->length; ++i) {
        printf("%s", a->pointer[i]); //Выводится какой-то мусор
    }

    //for (int i = 0; (i < a.length) && (i < b.length); ++i) {

        //printf("%s and %s = %i\n",a.pointer[i],b.pointer[i],a.pointer[i]!=b.pointer[i]);
        //if(a.pointer[i]!=b.pointer[i]){
           // d++;
        //}
    //}
}

int main() {
    signed char buffer[MAX_BUFFER];
    int n;
    T_String *strings;
    printf("Введите кол-во слов: ");
    scanf("%i",&n);
    strings = malloc(n * sizeof(T_String));

    for (int i = 0; i < n; ++i) {
        scanf("%s",buffer);
        strings[i].pointer = malloc(strlen(buffer) * sizeof(char));
        strcpy(strings[i].pointer,buffer);
        strings[i].length = strlen(buffer);
    }

    if(!equals_len(strings,n)){
        //InsertionSort(strings,n);
    }

    for (int i = 0; i < n-1; ++i) {
        for (int j = i+1; j < n; ++j) {
            if(word_distantion(&(strings[i]), &(strings[j]))>0){
                //printf("%s and %s = %i\n",a[i].pointer,a[j].pointer,word_distantion(a[i],a[j]));
            }
        }
    }

    return 0;
}
c
  • 1 个回答
  • 10 Views
Martin Hope
alex-rudenkiy
Asked: 2020-04-21 22:03:58 +0000 UTC

如何使用结构和子程序模块间?

  • 1

请告诉我如何与结构和子程序进行联运工作?特别是,我在使用 Student 和 Marks 结构以及诸如 action 这样的函数时遇到问题,它对给定的 Student 结构数组执行给定的操作(执行作为参数传递的函数)

主程序

#include <stdio.h>
#include <rpc.h>

int main() {
    SetConsoleOutputCP(CP_UTF8); //Windows10

    size_t n;

    printf("Введите число студентов: ");
    scanf("%i", &n);

    Student *students = Read_Students(n);

    action(students, n, &Sort);

    for (size_t i=0;i<n;i++)
        printf("%i %i\n",students[i].marks.History,students[i].marks.Math);

    return 0;
}

行动.c

#include <rpcndr.h>

void InsertionSort(struct Student *students, int *arr, int n) {
    size_t tmpIntElement, location;
    Student tmpStudElement;

    for (size_t i = 1; i < n; i++) {
        tmpIntElement = arr[i];
        tmpStudElement = students[i];
        location = i - 1;
        while (location >= 0 && arr[location] < tmpIntElement) {
            arr[location + 1] = arr[location];
            students[location + 1] = students[location];

            location = location - 1;
        }
        arr[location + 1] = tmpIntElement;
        students[location + 1] = tmpStudElement;
    }
}

void Sort(Student *students, int n) {
    int *arr = getSredneeArr(students, n);
    if (!equals_el(arr, n)) {
        InsertionSort(students, arr, n);
    }
}

void action(Student *students, int n, void (*f)(Student *,int)) {
    f(students,n);
}

函数.c

#include <stdio.h>
#include <dxtmpl.h>

void Read_Student(Student *student) {
    printf("\tИмя студента : ");
    scanf("%s", student->name);
    puts("");

    printf("\tФамилия студента : ");
    scanf("%s", student->surname);
    puts("");

    printf("\tОценка студента по\n");

    printf("\t\tМатематике = ");
    scanf("%i", &student->marks.Math);

    printf("\t\tИстории = ");
    scanf("%i", &student->marks.History);
    puts("");
}

int *getSredneeArr(struct Student *students, int n) {
    int *arr = malloc(n * sizeof(int));
    for (size_t i = 0; i < n; i++)
        arr[i] = (students[i].marks.Math + students[i].marks.History) / 2;
    return arr;
}

int equals_el(int *arr, int n) {
    size_t i, j;
    for (i = 0; i < n - 1; ++i) {
        for (j = i + 1; j < n; ++j) {
            if (arr[i] == arr[j]) {
                break;
            }
        }
    }
    return arr[i] == arr[j];
}

Student *Read_Students(int n) {
    Student *students;

    students = (Student *) malloc(sizeof(Student) * n);
    puts("");

    for (size_t i = 0; i < n; i++) {
        printf("Cтудент %i\n\n", i + 1);
        Read_Student(&students[i]);
    }

    return students;
}

结构体.c

#define MAXBuffer 256

typedef struct Marks {
    int Math;
    int History;
} Marks;

typedef struct Student {
    char name[MAXBuffer];
    char surname[MAXBuffer];
    int srMark;
    Marks marks;
} Student;
c
  • 2 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5