python-3.5

TensorFlow: AttributeError: 'Tensor' object has no attribute 'log10'

孤人 提交于 2019-12-10 22:58:47
问题 I have been using tensorflow with python3 support. There is line in my code which throws me an error. The error here : return -10. * np.log10(K.mean(K.square(y_pred - y_true))) AttributeError: 'Tensor' object has no attribute 'log10' 回答1: you can do like this: return 10.0 * K.log(1.0 / (K.mean(K.square(y_pred - y_true)))) / K.log(10.0) 来源: https://stackoverflow.com/questions/41826531/tensorflow-attributeerror-tensor-object-has-no-attribute-log10

How to create and activate virtual environment in windows 10 using bash command

北城以北 提交于 2019-12-10 21:25:48
问题 I am trying to activate my virtual environment using bash command in windows 10. I am using python 3.5.1 . F:\Python\Python35 is the location where my python.exe is located. My virtual environment's name is myvenv and F:\Python\virtualenvironment\myvenv is the location where my virtual environment is located. I created my virtual environment using following bash command Nazem Mahmud@DESKTOP-VQR06GL MINGW64 /f/Python/virtualenvironment $ python -m venv myvenv But i can't activate it now. I

Cube root of negative real numbers

雨燕双飞 提交于 2019-12-10 19:47:47
问题 I'm trying to plot a quite complex function, i.e. log(x/(x-2))**Rational(1,3) . I'm working only with real numbers. If I try to plot it, sympy only plots the x>2 part of it. I found that actually complex numbers come into play and, for example, root(-8,3).n() gives: 1.0+1.73205080756888i Which is reasonable, even though it's not what I was looking for (because I'm only interested in the real result). Reading sympy › principle root I found that real_root(-8,3) gives -2 as expected. But I still

Python Dump YAML Using Double Quotes Around Strings

纵饮孤独 提交于 2019-12-10 19:25:00
问题 In Python 3.5, I have the following dictionary to be dumped into a .yaml file. D={'name': 'mydata', value: {'x': 1, 'y': 2, 'z':3}} When I run the following code: import ruamel import ruamel.yaml as yaml D={'name': 'mydata', 'value': {'x': 1, 'y': 2, 'z':3}} yaml.round_trip_dump(D, open('my_yaml.yaml', 'w'), default_flow_style=False, indent=4) The resulting my_yaml.yaml looks like the following: name: mydata value: z: 3 x: 1 y: 2 My question is, is there a handy way to write double quotes

Invalid JSON Payload error with python google sheets API

倾然丶 夕夏残阳落幕 提交于 2019-12-10 17:54:29
问题 I'm trying to use the google sheets API to append new rows to an existing google sheet. Authentication already happens successfully and code is able to read the contents of the sheet. However, when I try to use service.spreadsheets().values().append(...) , I get the following HttpError: "Invalid JSON payload received. Unknown name "": Root element must be a message." Here is my code: from json import dumps as jsdumps credentials = get_credentials() http = credentials.authorize(httplib2.Http()

How to set the spaces in a string format in Python 3

时间秒杀一切 提交于 2019-12-10 17:33:23
问题 How can I set up the string format so that I could use a variable to ensure the length can change as needed? For example, lets say the length was 10 at first, then the input changes then length becomes 15. How would I get the format string to update? length = 0 for i in self.rows: for j in i: if len(j) > length: length = len(j) print('% length s') Obviously the syntax above is wrong but I can't figure out how to get this to work. 回答1: Using str.format >>> length = 20 >>> string = "some string

Forcing UTF-8 over cp1252 (Python3)

馋奶兔 提交于 2019-12-10 16:31:48
问题 I've written some code that makes use of the Biopython Entrez wrapper. Code was working fine on my previous Win10 laptop (Python 3.5.1), but I've just ported the code to a new Win10 laptop with the same versions of every package and Python installed and I'm now getting a decode error. The traceback error leads to a function that fetches text - it's attempting to decode the text using cp1252 when it should be using UTF-8. I know that similar questions have been asked, but none have dealt with

Is it possible to inherit from class with Generic in Python?

隐身守侯 提交于 2019-12-10 15:56:24
问题 Since Python 3.5 you can use Generics and other interesting stuff described in PEP-0484. I tried that and here's a code I have: from typing import TypeVar, Generic, Optional ... _T = TypeVar('T') _S = TypeVar('S') class Pool(Generic[_S, _T]): def __init__(self) -> None: self.pool = dict() ... getters and setters here... This code works perfectly and does what is expected. Then I decided to extend this class to make some additional work. That's how I did that: class PoolEx(Pool[_S, _T]):

Uploading xgboost to azure machine learning: %1 is not a valid Win32 application\r\nProcess returned with non-zero exit code 1

走远了吗. 提交于 2019-12-10 12:22:35
问题 I've tried to upload the xgboost python library to Azure ML, however it claim that my library is not a Win32 application. I've made sure to install the 32 bit version of the package and i'm running conda 32 bit as well. I downloaded the library from: http://www.lfd.uci.edu/~gohlke/pythonlibs/#xgboost and chose the 32 bit python 3.5 version. Python installation as below. This is the error I get returned azure ml error Here is my installation of anaconda conda installation Can anyone see where

formatting numbers in pandas

删除回忆录丶 提交于 2019-12-10 11:54:50
问题 for a pandas.DataFrame: df min max mean a 0.0 2.300000e+04 6.450098e+02 b 0.0 1.370000e+05 1.651754e+03 c 218.0 1.221550e+10 3.975262e+07 d 1.0 5.060000e+03 2.727708e+02 e 0.0 6.400000e+05 6.560047e+03 I would like to format the display such as numbers show in the ":,.2f" format (that is ##,###.##) and remove the exponents. I tried: df.style.format("{:,.2f}") which gives: <pandas.io.formats.style.Styler object at 0x108b86f60> that i have no idea what to do with. Any lead please? 回答1: try this