鱼C论坛

 找回密码
 立即注册
查看: 1413|回复: 3

numpy array 数据类型问题

[复制链接]
发表于 2021-9-18 12:09:18 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
大家好,我在一个下载的程序上做了一些修改,其中有个问题

我print了某个变量的类型,维度及其值
print(type(A))
print(A.shape)
print(A)

结果如下:
原代码中数据的类型是
<class 'numpy.ndarray'> (3,)
[-1.48029737e-17 -1.48029737e-17 -3.08148791e-33]

而我传入的数据类型是
<class 'numpy.ndarray'> (3, 1)
[[-4.44089210e-17]
[-1.85037171e-17]
[ 1.11022302e-17]]

请问怎么把<class 'numpy.ndarray'> (3, 1) 类型转换成<class 'numpy.ndarray'> (3,)

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-9-18 12:28:43 | 显示全部楼层
我用你的代码:
import numpy as np
A = np.array([-1.48029737e-17, -1.48029737e-17, -3.08148791e-33])

print(type(A))
print(A.shape)
print(A)
结果:
<class 'numpy.ndarray'>
(3,)
[-1.48029737e-17 -1.48029737e-17 -3.08148791e-33]
(3,) 不是你想要的吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-18 12:35:25 | 显示全部楼层


楼楼,Python numpy 的数组 (3, 1) 就是 (3, )  不需要更改~

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-18 13:19:52 | 显示全部楼层
本帖最后由 lqhenwunai 于 2021-9-18 13:22 编辑

谢谢大家的回复!!!
如果不嫌长,我把相关代码贴一下
        for i in range(1):
              # find the nearest neighbors between the current source and destination points
                distances, indices = nearest_neighbor(src[:dim,:].T, dst[:dim,:].T)
                # compute the transformation between the current source and nearest destination points
                Transformation_Mat , Rotation, translation = best_fit_transform(src[:dim,:].T, dst[:dim,indices].T)

                # update the current source
                src = np.dot(Transformation_Mat, src)
                # check error
                mean_error = np.mean(distances)
                if np.abs(prev_error - mean_error) < thresh:
                        break
                prev_error = mean_error

        # calculate final transformation
        Transformation_Mat,Rotation,translation = best_fit_transform(chull1, src[:dim,:].T)
这里我只做一次循环,调用best_fit_transform 函数,并且在循环外再调用一次。

而在best_fit_transform函数中,我有这么一段话:
        tmp=np.dot(R,centroid_A.T)
        tmp=np.array(tmp)
        t = centroid_B.T - tmp

        print("check t...")
        print(type(tmp),tmp.shape)
        print(centroid_B.T)
        print(np.dot(R,centroid_A.T))
        print(t)
        print("..................")
        # homogeneous transformation
        T = np.identity(dim+1)
        T[:dim, :dim] = R
        T[:dim, dim] = t

不懂为什么,两次打印出来的tmp就如一楼所显示的一样,而这造成的后果就是得到的t第一次是1×3的行向量,第二次就是个3*3的矩阵了。然后后面对T赋值就报错了。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-7 08:19

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表