我在下面的代码中使用normalize函数.我的理解是,对直方图进行标准化会导致这些箱子总和为一个?但是当我把它们全部添加起来时,我会得到比一个更高的结果.我不知道我做错了什么或者误解了这个功能是做什么的?
//read in image
Mat img = imread("image.jpg",1);
vector<Mat> planes;
split(img, planes);
//calculate hist
MatND hist;
int nbins = 256; // hold 256 levels
int hsize[] = { nbins }; // one dimension
float range[] = { 0, 255 };
const float *ranges[] = { range };
int chnls[] = {0};
calcHist(&planes[0], 1, chnls, Mat(), hist,1,hsize,ranges);
//normalise
normalize(hist,hist,1);
float tot = 0;
for( int n = 0;n < nbins; n++ )
{
float binVal = hist.at<float>(n);
tot+=binVal;
}
cout<<tot;
Run Code Online (Sandbox Code Playgroud) 我正在做一个2D坦克炮塔游戏,你在屏幕中间旋转坦克,点击你的左按钮然后一个小弹丸移动到那个位置.
我目前正处于当前位置和所需位置的位置,我现在需要做的是获得这两个点的大小,这应该返回1或0.
这是我的C++ VectorClass幅度函数:
float vector2D::magnitude(vector2D vec2)//<! Vector magnitude
{
float result;
result = (sqrt(x*vec2.x)+(y*vec2.y));
return result;
}
Run Code Online (Sandbox Code Playgroud)
这是我将我想要的和当前位置标准化的代码:
currentPos.x = laserTexture.getSize().x/2.0f;
currentPos.y = laserTexture.getSize().y/2.0f;
desiredPos.x = sf::Mouse::getPosition().x;
desiredPos.y = sf::Mouse::getPosition().y;
normalisedLocation = magnitude(desiredPos - currentPos);
Run Code Online (Sandbox Code Playgroud)
当前位置与我的laserTexture中间相关,这是屏幕中间的固定旋转点.
我想要的位置是鼠标点击,它返回X和Y的位置(这是有效的).
数学不是我的强项,所以当谈到编程这类东西时,我比其他人做的更挣扎,所以它需要我更长时间/我会想出一些不太优雅的解决方案.
我的最终目标是获得标准化的位置,然后当点击鼠标左键时,坦克炮塔将会发射,并且射弹将移动到所需的位置.
所以澄清一下:
谢谢
我正在使用带有Tensorflow神经网络的Anaconda.我的大多数数据都存储有pandas
.
我试图预测加密货币市场.我知道很多人可能正在这样做,而且很可能不会非常有效,我主要是为了熟悉Tensorflow和Anaconda工具.
我对此很新,所以如果我做错了什么或不是最理想的,请告诉我.
以下是我如何获取和处理数据:
DataFrames
DataFrames
DataFrame
0.0-1.0
将每列(独立地)标准化为新列DataFrame
df = (df - df.min()) / (df.max() - df.min())
现在,我的问题是,我如何干净地规范化然后将这些数据非标准化?我意识到,如果我想对数据进行非标准化,我将需要存储初始值df.min()
和df.max()
值,但这看起来很丑陋并且感觉很麻烦.
我知道我可以用数据标准化数据sklearn.preprocessing.MinMaxScaler
,但据我所知,我不能使用这个来对数据进行非标准化.
这可能是我在这里做了一些根本错误的事情,但如果没有一种干净的方法来使用Anaconda或其他库来规范化和非规范化数据,我会感到非常惊讶.
我有以下df:
Date Event_Counts Category_A Category_B
20170401 982457 0 1
20170402 982754 1 0
20170402 875786 0 1
Run Code Online (Sandbox Code Playgroud)
我正在为回归分析准备数据,并希望标准化Event_Counts列,以便它与类别类似.
我使用以下代码:
from sklearn import preprocessing
df['scaled_event_counts'] = preprocessing.scale(df['Event_Counts'])
Run Code Online (Sandbox Code Playgroud)
虽然我收到了这个警告:
DataConversionWarning: Data with input dtype int64 was converted to float64 by the scale function.
warnings.warn(msg, _DataConversionWarning)
Run Code Online (Sandbox Code Playgroud)
它似乎有效; 有一个新专栏.但是,它有负数,如-1.3
我认为比例函数的作用是从数字中减去均值,并将其除以每一行的标准差; 然后将结果的min添加到每一行.
这种方式对熊猫不起作用吗?或者我应该使用normalize()函数还是StandardScaler()函数?我希望标准化列的比例为0到1.
谢谢
我是Python的新手,有没有可以对数据进行规范化的函数?
例如,我在范围0 - 1
示例中设置了一组列表:[0.92323, 0.7232322, 0,93832, 0.4344433]
我想将所有这些值标准化 0.25 - 0.50
谢谢,
我有一个矩阵:
S = [ -1.0400 4.9100 4.1000 -3.5450 -0.6600 -0.9300 4.3950 -1.0650 2.9850 -4.9800 0.2100;
-0.5200 -4.3150 -3.0950 0.5700 4.4700 1.1500 3.1350 0.6450 0.3750 -4.9150 -2.1150;
5.0000 5.0000 5.0000 5.0000 5.0000 5.0000 5.0000 5.0000 5.0000 5.0000 5.0000 ];
Run Code Online (Sandbox Code Playgroud)
我想将列转换为单位向量,所以我使用for
循环
for i=1:size(S,2)
S(:,i) = S(:,i) / norm( S(:,i) );
end
Run Code Online (Sandbox Code Playgroud)
有没有办法在MATLAB中更有效地完成这项工作?
当 uint16 图像的最大像素值不是 65535(它小于该值)(实际上是 2970)时,我需要将图像从 uint16 转换为 uint8,以便将其保存到磁盘。我注意到 scikit-image 有用于此类转换的方法img_as_ubyte 。看来这个方法将 65535 转换为 255,并且所有值都与此成比例。问题是图像的最大值为 2000,转换为 12 后会损失大量分辨率。我也在考虑将图像保存为 numpy
我尝试使用此处提出的 rescale 函数以及 cv2.normalize 函数。但是,我注意到 cv2.normalize 函数创建了dtype=uint16的图像。
另外,我检查了 matlab 中的 mat2gray,发现 cv2.normalize 与 mat2gray 比普通 python 中带有标准化函数的方法更相似。
使用普通的Python:
orig_min = mammogram_dicom.min()
orig_max = mammogram_dicom.max()
target_min = 0.0
target_max = 255.0
mammogram_scaled = (mammogram_dicom-orig_min)*((target_max-
target_min)/(orig_max-orig_min))+target_min
mammogram_uint8_by_function = mammogram_scaled.astype(np.uint8)
Run Code Online (Sandbox Code Playgroud)
我觉得使用 np.uint8 很奇怪,我宁愿不使用它,但这是我进入 uint 8 的唯一方法
对于 cv2.normalized 我还必须使用 np.uint8 来获取 uint8:
mammogram_uint8_by_cv2 = np.zeros(mammogram_dicom.shape).astype(np.uint8)
mammogram_uint8_by_cv2 = cv2.normalize(mammogram_dicom, None, 0, …
Run Code Online (Sandbox Code Playgroud) 移动物体中的代码:
ObjectX.Location.Add(Velocity * Utils.GetMoveDir(start, destination));
Run Code Online (Sandbox Code Playgroud)
实用功能:
public static PointF GetMoveDir(PointF start, PointF destination)
{
PointF substraction = destination.SubStract(start);
if (substraction == PointF.Empty) // If-statement is needed because normalizing a zero value results in a NaN value
return PointF.Empty;
else
return substraction.Normalize(); // <<<< I need something for this
}
Run Code Online (Sandbox Code Playgroud)
扩展我无法工作:
public static PointF Normalize(this PointF A)
{
throw new NotImplementedException(); // How do I solve this to make it like: http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.vector2.normalize.aspx
}
Run Code Online (Sandbox Code Playgroud)
请注意,我不使用XNA框架.
我很不幸进入了一所不关心学生为大学做准备的高中,但我正在学习一些游戏编程,以及我得到的所有编程,但我正在学习游戏 AI 课程,我们正在学习 FSM和 AI 运动,我遇到了“规范化”,研究了它,它有点道理,但我将如何在游戏编程中使用它?也许我只是不太了解这个概念(从来没有真正上过代数课,虽然我每天在其他编程中都使用高级数学,但是我边学边学),但我只是不明白为什么我需要要做到这一点。
所以说我有一个大的浮动列表,我想将它们全部归一化为min
和之间的值max
.例如,{2, 5, 10}
与min = 0
和max = 2
一组的结果{0.4, 1, 2}
.
我目前的算法是
我的问题是一般的算法 - 是否可以O(n)
代替进行此操作O(2n)
?
我需要一个C#代码片段来计算表面和顶点法线.表面的种类是三角形3D闭合网格.所需的代码段必须能够使用顶点集和三角形指示.这些现在可以使用了.3D网格物体的表面不光滑,因此需要进行平滑处理.
你可以帮帮我吗.
嗨,刚开始使用Matlab,我想知道如何在矩阵中重新缩放数据.我有一个N行×M列的矩阵,并希望将列中的数据重新缩放到介于-1和1之间.
每列包含从0到10,000的比例变化到0到1之间的值,我想要归一化到-1和1之间的原因,因为这些值将在神经网络中用作变换的输入值基于正弦的功能.
normalize ×12
python ×3
c# ×2
c++ ×2
matlab ×2
matrix ×2
opencv ×2
pandas ×2
vector ×2
algorithm ×1
magnitude ×1
normals ×1
numpy ×1
optimization ×1
performance ×1
python-3.x ×1
scale ×1
scikit-image ×1
standardized ×1
tensorflow ×1