NumSharp

github地址:https://github.com/SciSharp/NumSharp

High Performance Computation for N-D Tensors in .NET, similar API to NumPy.

NumSharp (NS) is a NumPy port to C# targetting .NET Standard.


NumSharp is the fundamental package needed for scientific computing with C# and F#.

Is it difficult to translate python machine learning code into .NET? Because too many functions can’t be found in the corresponding code in the .NET SDK. NumSharp is the C# version of NumPy, which is as consistent as possible with the NumPy programming interface, including function names and parameter locations. By introducing the NumSharp tool library, you can easily convert from python code to C# or F# code. Here is a comparison code between NumSharp and NumPy (left is python, right is C#):

Bold Features

  • Use of Unmanaged Memory and fast unsafe algorithms.
  • Broadcasting n-d shapes against each other. (intro)
  • NDArray Slicing and nested/recusive slicing (nd["-1, ::2"]["1::3, :, 0"])
  • Axis iteration and support in all of our implemented functions.
  • Full and precise (to numpy) automatic type resolving and conversion (upcasting, downcasting and other cases)
  • Non-copy - most cases, similarly to numpy, does not perform copying but returns a view instead.
  • Almost non-effort copy-pasting numpy code from python to C#.
  • Wide support for System.Drawing.Bitmap. (read more)

Implemented APIs

The NumPy class is a high-level abstraction of NDArray that allows NumSharp to be used in the same way as Python's NumPy, minimizing API differences caused by programming language features, allowing .NET developers to maximize Utilize a wide range of NumPy code resources to seamlessly translate python code into .NET code.

Install NumSharp in NuGet

PM> Install-Package NumSharp

How to use

using NumSharp;var nd = np.full(5, 12); //[5, 5, 5 .. 5]
nd = np.zeros(12); //[0, 0, 0 .. 0]
nd = np.arange(12); //[0, 1, 2 .. 11]// create a matrix
nd = np.zeros((3, 4)); //[0, 0, 0 .. 0]
nd = np.arange(12).reshape(3, 4);// access data by index
var data = nd[1, 1];// create a tensor
nd = np.arange(12);// reshaping
data = nd.reshape(2, -1); //returning ndarray shaped (2, 6)Shape shape = (2, 3, 2);
data = nd.reshape(shape); //Tuple implicitly casted to Shape//or:
nd =   nd.reshape(2, 3, 2);// slicing tensor
data = nd[":, 0, :"]; //returning ndarray shaped (2, 1, 2)
data = nd[Slice.All, 0, Slice.All]; //equivalent to the line above.// nd is currently shaped (2, 3, 2)
// get the 2nd vector in the 1st dimension
data = nd[1]; //returning ndarray shaped (3, 2)// get the 3rd vector in the (axis 1, axis 2) dimension
data = nd[1, 2]; //returning ndarray shaped (2, )// get flat representation of nd
data = nd.flat; //or nd.flatten() for a copy// interate ndarray
foreach (object val in nd)
{// val can be either boxed value-type or a NDArray.
}var iter = nd.AsIterator<int>(); //a different T can be used to automatically perform cast behind the scenes.
while (iter.HasNext())
{//readint val = iter.MoveNext();//writeiter.MoveNextReference() = 123; //set value to the next val//note that setting is not supported when calling AsIterator<T>() where T is not the dtype of the ndarray.
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/234001.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Linux中vi常用命令-批量替换

在日常服务器日志查看中常用到的命令有grep、tail等&#xff0c;有时想查看详细日志&#xff0c;用到vi命令&#xff0c;记录下来&#xff0c;方便查看。 操作文件&#xff1a;test.properites 一、查看与编辑 查看命令&#xff1a;vi 文件名 编辑命令&#xff1a;按键 i&…

【实验】配置用户自动获取IPv6地址的案例

热门IT课程-试听视频文章浏览阅读49次。认证课程介绍&#xff1a;华为HCIA试听课程 &#xff1a; 华为HCIA试听课程&#xff1a;华为HCIA试听课程&#xff1a;华为HCIP试听课程&#xff1a;思科CCNA试听课程&#xff1a;思科CCNA试听课程&#xff1a;思科CCNA试听课程&#xff…

Linux scatterlist 详解

源码基于&#xff1a;Linux 5.4 约定&#xff1a; 芯片架构&#xff1a;ARM64内存架构&#xff1a;UMACONFIG_ARM64_VA_BITS&#xff1a;39CONFIG_ARM64_PAGE_SHIFT&#xff1a;12CONFIG_PGTABLE_LEVELS &#xff1a;3 0. 前言 之前在《Linux DMA... 零拷贝》博文分享了DMA 技…

【广州华锐互动】节约用水VR互动教育:身临其境体验水资源的珍贵!

随着技术的不断发展&#xff0c;虚拟现实&#xff08;VR&#xff09;技术在许多领域得到了广泛应用。在节水宣传教育方面&#xff0c;VR技术也展现出了其独特的优势。与传统宣传教育方式相比&#xff0c;节约用水VR互动教育具有更加沉浸式、互动性和实践性的特点&#xff0c;能…

修改el-table表头样式

<style lang"scss" scoped> ::v-deep .el-table {.el-table__header-wrapper, .el-table__fixed-header-wrapper {th {word-break: break-word;background-color: #f8f8f9;color: #515a6e;height: 40px;font-size: 13px;}} } </style>

Java多线程其他细节知识

并发、并行 进程 并发的含义 并行的理解 线程的生命周期

代码随想录第二十天(一刷C语言)|修剪二叉搜索树将有序数组转换为二叉搜索树把二叉搜索树转换为累加树

创作目的&#xff1a;为了方便自己后续复习重点&#xff0c;以及养成写博客的习惯。 一、修剪二叉搜索树 思路&#xff1a;使用递归的方法&#xff0c;不停的判断节点与所给区间是否相符&#xff0c;相符则对本节点的做右节点做递归操作并返回本节点。 ledcode题目&#xff…

2023年第三届中国高校大数据挑战赛思路及代码

比赛时间&#xff1a;2023.12.28 08:00 至 2023.12.31 20:00 赛题方向介绍 1、大数据统计分析方向 涉及内容包含&#xff1a;数据的清洗、数据的预测、数据之间的关联分析、综合评价、分类与判别等 2、文本或图象分析方向 涉及内容包含&#xff1a;计算机视觉基础、特征匹配…

电商干货:怎么从客服的角度降低退款率?

【售前阶段】 订单状态为[买家已付款](未发货) →选择原因:价格贵 建议处理方式:客服主动和买家说明产品 有哪些功能优势、店铺有哪些服务优势(如10年质保免费以日换新、运费险、7/15天无理由、30天保价等) 注意事项: 注重回复的话术。看挽单话术是否需要优化。是否太过于…

Redis哈希对象(listpack介绍)

哈希对象的编码可以是ziplist或者hashtable。再redis5.0版本之后出现listpack&#xff0c;为了是代替ziplist。 一. 使用ziplist编码 ziplist编码的哈希对象使用压缩列表作为底层实现&#xff0c;每当有新的键值对要加入到哈希对象时&#xff0c;程序都会先将保存了键值对的键…

代码demo-内部订单批量投料

为了简化用户操作&#xff0c;开发内部订单批量投料功能 用户可以批量上传&#xff0c;或者选择对应的物料&#xff0c;输入库位和内部订单号后进行过账操作 对用户选择的内部订单做校验&#xff0c;内部订单是否正确 内部订单的公司是否和工厂对应的公司一致等等 下面展示…

python中,or、not的用法

or的用法 在python中,or运算符是一个逻辑运算符&#xff0c;用于在多个条件中选择至少一个为真&#xff08;True&#xff09;的情况。 如果条件中的任意一个为真&#xff0c;整个表达式的结果就为真 如&#xff1a; 示例1: 检查两个数字中至少有一个正数 示例2: x True y …