Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Numpy属性错误:浮点对象没有attribtue 'arctan2‘

Numpy属性错误:浮点对象没有attribtue 'arctan2‘
EN

Stack Overflow用户
提问于 2022-02-11 02:59:07
回答 1查看 259关注 0票数 0

我一直在尝试实现这段代码,但是由于我对numpy非常陌生,所以我对这个错误知之甚少。

代码语言:javascript
运行
AI代码解释
复制
import numpy as np
from sympy import *
import matplotlib.pyplot as plt

def asSpherical(coord):
    x=coord[0]
    y=coord[1]
    z=coord[2]
    azimuth = np.arctan2(y,x)
    elevation = np.arctan2(z,np.sqrt(x**2 + y**2))
    r = np.sqrt(x**2 + y**2 + z**2)
    return [azimuth, elevation, r]

def ecefToEnu(lamb, phi, coord_set):
    # @param1 is lattitude
    # @param2 is longitude
    # @param3 is coordinate set in form of a list

    # R matrix of size 3x3
    # This transforms the ECEF coordinates to ENU
    trans_matrix = [
        [-np.sin(lamb), np.cos(lamb), 0],
        [-(np.cos(lamb))*np.sin(phi), -
         np.sin(lamb)*np.sin(phi), np.cos(phi)],
        [np.cos(lamb)*np.cos(phi), np.sin(lamb)*np.cos(phi), sin(phi)]
    ]
    # Performs the matrix multiplication
    enu_coords = np.matmul(trans_matrix, coord_set)
    # Returns a list of Cartesian Coordinates
    sph_coords = asSpherical(enu_coords)
    return sph_coords


coord_list = []
print("Enter the latitude")
latitude = float(input())
print("Enter the coordinate list:")
print("Enter X:")
coord_list.append(float(input()))
print("Enter Y:")
coord_list.append(float(input()))
print("Enter Z:")
coord_list.append(float(input()))
phiDegSet = np.arange(-180, 180, 1)
Nset = len(phiDegSet)
t0 = np.linspace(0, 24, Nset)
t0 = list(t0)

res = []
for i in range(0, 360):
    temp_list = ecefToEnu(latitude, phiDegSet[i], coord_list)
    res.append(temp_list)
elevDegSet = []
for i in res:
    elevDegSet.append(i[1])

这给了我一个错误:

代码语言:javascript
运行
AI代码解释
复制
    elevation = np.arctan2(z,np.sqrt(x**2 + y**2))
AttributeError: 'Float' object has no attribute 'arctan2'

我已经将该值作为float传递给该函数。即使是进口的numpy也能正常工作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-11 08:51:59

我在print之前添加了一个arctan语句

代码语言:javascript
运行
AI代码解释
复制
def asSpherical(coord):
    x=coord[0]
    y=coord[1]
    z=coord[2]
    print(x,y,z)
    azimuth = np.arctan2(y,x)
    ...

得到了这个结果:

代码语言:javascript
运行
AI代码解释
复制
....
ter the latitude
45
Enter the coordinate list:
Enter X:
45
Enter Y:
45
Enter Z:
45
-14.65116910723749 -76.54620448997258 -37.062720709188 - 45.0*sin(180)
Traceback (most recent call last):
  File "stack71078990.py", line 52, in <module>
    temp_list = ecefToEnu(latitude, phiDegSet[i], coord_list)
  File "stack71078990.py", line 31, in ecefToEnu
    sph_coords = asSpherical(enu_coords)
  File "stack71078990.py", line 11, in asSpherical
    elevation = np.arctan2(z,np.sqrt(x**2 + y**2))
AttributeError: 'Add' object has no attribute 'arctan2'

z-37.062720709188 - 45.0*sin(180),其中sin(180)sympy表达式。

我在sin(phi)表达式中看到了trans_matrix。由于from sympy import *sin (而不是np.sin)是sympy函数。

删除该导入(正如我评论的那样)会引发:

代码语言:javascript
运行
AI代码解释
复制
Traceback (most recent call last):
  File "stack71078990.py", line 52, in <module>
    temp_list = ecefToEnu(latitude, phiDegSet[i], coord_list)
  File "stack71078990.py", line 26, in ecefToEnu
    [np.cos(lamb)*np.cos(phi), np.sin(lamb)*np.cos(phi), sin(phi)]
NameError: name 'sin' is not defined

将其更改为np.sin (与定义中的其他函数一样),可以让脚本运行而不会出错。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71078990

复制
相关文章
基于MNIST手写体数字识别--含可直接使用代码【Python+Tensorflow+CNN+Keras】
利用数据集:MNIST http://yann.lecun.com/exdb/mnist/ 完成手写体数字识别 紫色yyds
司六米希
2022/11/15
5.5K0
基于MNIST手写体数字识别--含可直接使用代码【Python+Tensorflow+CNN+Keras】
Keras中创建LSTM模型的步骤[通俗易懂]
本文是对The 5 Step Life-Cycle for Long Short-Term Memory Models in Keras的复现与解读,新手博主,边学边记,以便后续温习,或者对他人有所帮助
全栈程序员站长
2022/10/03
3.8K0
Keras中创建LSTM模型的步骤[通俗易懂]
[Deep-Learning-with-Python]神经网络入手学习[上]
网络层堆叠形成网络模型,网络模型由输入数据得到预测值。损失函数比较预测值与实际值,得到损失函数值:用来评估预测结果的好坏;优化方法用损失值来更新网络模型的权重系数。
用户1631856
2018/08/01
1.1K0
[Deep-Learning-with-Python]神经网络入手学习[上]
【推荐系统】基于文本挖掘的推荐模型【含基于CNN的文本挖掘、python代码】
二维卷积网络是通过将卷积核在二维矩阵中,分别从width和height两个方向进行滑动窗口操作,且对应位置进行相乘求和。而图像则正是拥有二维特征像素图,所以图像应用卷积网络是二维卷积网络。
司六米希
2022/11/15
1.4K0
【推荐系统】基于文本挖掘的推荐模型【含基于CNN的文本挖掘、python代码】
MLK | Keras 基础模型调参指南
上一篇文章讲解了如何简易入门Keras,大致给出了一个深度学习模型,但对于模型如何调参就没有太过于深入讲解,今天继续写一篇文章来整理下 Keras 深度学习模型的调参教程,希望可以对大家有所帮助。
Sam Gor
2019/08/09
1.2K0
MLK | Keras 基础模型调参指南
Python安装TensorFlow 2、tf.keras和深度学习模型的定义
使用tf.keras,您可以设计,拟合,评估和使用深度学习模型,从而仅用几行代码即可做出预测。它使普通的深度学习任务(如分类和回归预测建模)可供希望完成任务的普通开发人员使用。
拓端
2020/11/03
1.7K0
第10章 使用Keras搭建人工神经网络·精华代码
电脑上看效果好,不用左右滑屏。都调好了,复制粘贴就可以在PyCharm里直接跑起来。 # -*- coding: utf-8 -*- # 需要安装和引入的包有tensorflow\pandas\numpy\matplotlib\scikit-learn # 使用pip安装:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ tensorflow pandas matplotlib scikit-learn import numpy as
SeanCheney
2019/10/21
1.3K0
TensorFlow 基础学习 - 1
了解机器学习的一些基础功能,一些基础用法,然后在我们的实际工作中创造出更多的火花。
叉叉敌
2021/12/06
4010
TensorFlow 基础学习 - 1
用Python实现神经网络(附完整代码)!
在学习神经网络之前,我们需要对神经网络底层先做一个基本的了解。我们将在本节介绍感知机、反向传播算法以及多种梯度下降法以给大家一个全面的认识。
Datawhale
2020/12/07
5.7K0
《机器学习实战:基于Scikit-Learn、Keras和TensorFlow》第10章 使用Keras搭建人工神经网络
下载本书代码和电子书:https://www.jianshu.com/p/4a94798f7dcc
SeanCheney
2019/10/16
3.4K0
《机器学习实战:基于Scikit-Learn、Keras和TensorFlow》第10章 使用Keras搭建人工神经网络
keras中的损失函数
损失函数是模型优化的目标,所以又叫目标函数、优化评分函数,在keras中,模型编译的参数loss指定了损失函数的类别,有两种指定方法:
用户3578099
2020/03/31
2.2K0
TensorFlow快餐教程:程序员快速入门深度学习五步法
作为一个程序员,我们可以像学习编程一样学习深度学习模型开发。我们以 Keras 为例来说明。
IT派
2018/07/30
4860
TensorFlow快餐教程:程序员快速入门深度学习五步法
Keras 中神经网络模型的 5 步生命周期
https://machinelearningmastery.com/5-step-life-cycle-neural-network-models-keras/
PM小王
2019/07/01
2K0
Keras 中神经网络模型的 5 步生命周期
TensorFlow与PyTorch — 线性回归
如果是深度学习和神经网络的新手,那么一定遇到过“ TensorFlow ”和“ PyTorch ” 这两个术语。这是在数据科学领域中使用的两个流行的深度学习框架。
代码医生工作室
2020/06/01
1.1K0
(数据科学学习手札44)在Keras中训练多层感知机
  Keras是有着自主的一套前端控制语法,后端基于tensorflow和theano的深度学习框架,因为其搭建神经网络简单快捷明了的语法风格,可以帮助使用者更快捷的搭建自己的神经网络,堪称深度学习框架中的sklearn,本文就将基于Keras,以手写数字数据集MNIST为演示数据,对多层感知机(MLP)的训练方法进行一个基本的介绍,而关于多层感知机的相关原理,请移步数据科学学习手札34:https://www.cnblogs.com/feffery/p/8996623.html,本文不再赘述。
Feffery
2018/07/29
1.5K0
TensorFlow快餐教程:程序员快速入门深度学习五步法
作为一个程序员,我们可以像学习编程一样学习深度学习模型开发。我们以 Keras 为例来说明。
AI科技大本营
2018/07/23
4250
TensorFlow快餐教程:程序员快速入门深度学习五步法
点击加载更多

相似问题

Keras -训练损失与验证损失

10

为什么Keras训练得很好,但返回错误的预测呢?

10

验证损失低于训练损失,并在Keras中减少损失

121

Keras model.fit() -使用了哪种训练算法?

14

Keras模型训练得很好,但预测值相同。

12
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档