如何初始化n维矩阵? [英] how to initialize n-dimensional matrix ?

查看:92
本文介绍了如何初始化n维矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在努力编写一个以int n为参数的函数,在函数内部我需要初始化一个n维矩阵并返回指针到初始化矩阵。


如果你知道任何我可以阅读相关事项的在线资源,那么请注意为我提供相同的信息。由于我很长时间以来一直在努力解决这个问题,到目前为止我还没有找到令人信服的答案。



谢谢

hi everybody,

I am struggling to write a function which takes an int n as parameter, and inside the function I need to initilize a n-dimensional matrix and return the pointer to the initialized matrix.

If you know any online sources where I can read through the related matter then do care to provide me the same. As its been a long time since I am struggling with this problem and so far I havent been able to find a convincing answer.


Thanks

推荐答案

您需要做的是分配一块足够大的内存来容纳元素,然后返回该内存位置的地址。通过n维,你的意思是nxn矩阵,或n维矩阵(即3维,4维等)?
What you will have to do is allocate a piece of memory large enough to hold the elements, then return the address of that memory location. By n-dimensional, do you mean an n x n matrix, or a matrix with n dimensions (i.e. 3-dimensional, 4-dimensional, etc)?



您需要做的是分配一块足够大的内存来容纳元素,然后返回该内存位置的地址。 n维是指n x n矩阵,还是n维矩阵(即3维,4维等)?
What you will have to do is allocate a piece of memory large enough to hold the elements, then return the address of that memory location. By n-dimensional, do you mean an n x n matrix, or a matrix with n dimensions (i.e. 3-dimensional, 4-dimensional, etc)?



n * n是一个2d矩阵,我正在寻找的是一个n维矩阵,正在考虑递归分配它...但是无法弄清楚如何那样做。

n*n is a 2d matrix, what I am looking for is a n-dimesional matrix, Was thinking of recursively allocating it... but couldnt figure out how to do that.



n * n是一个2d矩阵,我正在寻找的是一个n维矩阵,正在考虑递归分配它...但无法弄清楚如何做到这一点。
n*n is a 2d matrix, what I am looking for is a n-dimesional matrix, Was thinking of recursively allocating it... but couldnt figure out how to do that.



您使用的是C还是C ++?在C中你可以使用malloc,在C ++中你可以使用new运算符。

Are you using C or C++? In C you coutld use malloc and in C++ you could use the new operator.


这篇关于如何初始化n维矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆