All Questions

Tagged with
78 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
6votes
0answers
1kviews

Representing a float or a binary as a 32 bit signed integer in R

I've been given a task to write an API for the AR.Drone 2.0 in R. I know it's probably not the wisest choice of language as there are good validated APIs written in Python and JS, but I took the ...
user avatar
  • 355
4votes
3answers
384views

How to preserve raster dataType in raster processing?

When doing raster math, for example raster1-raster2, the datatype of the output raster is 'FLT4S', even if the datatype ot both raster1 and raster 2 is 'INT2S'. How can I force the output to be 'INT2S'...
user avatar
  • 41
2votes
0answers
29views

IEEE integer standard

IEEE 754 defines floating point standards for computers. Is there such a similar standard for integers? Whenever I search for something like that, I end up at IEEE 754! C/C++ defines char, short, int, ...
user avatar
2votes
2answers
57views

I want to generate a for loop using decimals. I need the y value from the loop to create a list. This is a project and I cant use numpy

float object cannot be interpreted as an integer I want to generate a for loop using decimals. I need the y value from the loop to create a list. This is a project and I cant use numpy. Are there any ...
user avatar
2votes
1answer
253views

Stochastically rounding a float to an integer

I want a function (using Python 3.6+ if it's relevant) that will stochastically round a floating-point number to an integer in the following manner: Given a real number, x, let a = floor(x) and let b ...
user avatar
  • 533
2votes
0answers
478views

Recorded sound gets noisy/distorted when datatype is 32 bit float

I recorded sound from microphone on my computer by python with pyaudio. It works fine when sound is recorded in 16 bit integer as its data type. However, it does not work when it is recorded in 32 bit ...
user avatar
  • 79
2votes
1answer
318views

How do you convert data from float64 to int16 in python 3?

Currently I am using soundfile to read audio data from a wav file like so: import soundfile raw_data, sample_rate = soundfile.read(filename) Whilst I realise that you can select dtype=int16, I would ...
user avatar
2votes
1answer
2kviews

Getting only integers when dividing a pandas dataframe by a pandas series

I am trying to divide a dataframe by a pandas series and the result is only giving ones everywhere. Here is the example : This is my dataframe df This is my pandas series s this is what I am ...
user avatar
2votes
0answers
108views

Pandas - dtype shows int, but describe shows float

I have changed my variable age to an integer since it was stored as a float: sessions['age'] = sessions['age'].astype(int) Pandas dtypes returns an int: In: sessions['age'].dtype Out: dtype('int64')...
user avatar
  • 305
2votes
0answers
1kviews

default to floats in python

I'm writing some code that uses GPS coordinates but I'm running into a headache with python 2. I'm using the dronekit python library to be specific. Here's a sample of what I'm trying to do. ...
user avatar
  • 21
2votes
1answer
1kviews

Reliably detect integer overflow/underflow

I'm working on code that has to do the following with the result of a calculation: If the result exceeds the limit that can be represented in PHP's integer type then throw an exception. If the ...
user avatar
  • 30.1k
1vote
0answers
31views

C++ ignores the second input if the type of the first input in not correct

This is the code: #include <iostream> using namespace std; int main() { int var1; float var2; cout << "input var1:"; cin >> var1; cout << "...
user avatar
  • 13
1vote
3answers
357views

Determine if a variable is a float or an integer in java

I need to write a program which uses multiple methods called average which return the average of those values, if both are ints the value returned should be an int, and if one or more is a floating ...
user avatar
1vote
1answer
40views

What's the easiest way to prevent a user from entering a letter when the program asks for a number?

Say I have a float variable called "varFloat" and I use cin to allow the user to input a number, how can I prevent the user from entering a letter? I have a calculator program that breaks if a letter ...
user avatar
1vote
0answers
31views

Should Random Forest in R take far longer to run with floats vs integers?

I have a dataset that I am running a Random Forest routine on in R (using caret). The raw data (all integers) finishes pretty rapidly; if I normalize so that the values are all floats (between 0 and ...
user avatar
1vote
1answer
92views

What integer operations can be efficiently emulated using floating point?

I need to work on a processor that natively supports 16-bit integer math and 32-bit floating point operations. Some of the algorithms that are targeting the processor require integer math accuracy ...
user avatar
  • 7,210
1vote
0answers
45views

Why does adding the integer 1 to another integer, then cast to a float give me .99?

I am in a visual programming class, trying to make a GUI in Processing that will eventually control an Arduino MeArm. I have a controlP5 element for each of the 4 servos, whose values are stored as ...
user avatar
  • 11
1vote
1answer
66views

JavaScript: Decimal part of a float is caught by integer regex

I am trying to differentiate if a user's input is a float or an integer. However, when a user enters a float, the whole input is considered a float but the decimal part of it is considered an integer, ...
user avatar
  • 21
1vote
1answer
2kviews

Comparing a Float with an Int in SSRS

I have a field where I'm using LEN() to calculate the string length and then I'm comparing this to a value generated by AVG(CONVERT(FLOAT,LEN(some_field))). The point of the comparison is to do THIS ...
user avatar
  • 1,278
1vote
4answers
1kviews

how to get percentage rounded to an integer

Example: 150 blue balls 250 red balls What are the percentage of blue balls? 150 divided by total balls (400) equals 38 percent if I set it blue_balls = 1.0 * number_of_blue_balls / (...
user avatar
1vote
2answers
1kviews

Traceback error: TypeError float object cannot be interpreted as an integer

Could someone help me figure out the problem I have with this? def marbles(): marbles = 0 while True: try: x = eval(input("How many marbles? ")) except ValueError: ...
user avatar
1vote
2answers
2kviews

Converting remainder of a floating point float/double into an int

I have a double (or float) number x: x = 1234.5678; Now, the question is, how do break down the number into 2 int's whereas int1 would get the number before the point, and int2 is the number after ...
user avatar
  • 2,222
1vote
3answers
609views

comparing floats precisely after a cross product operation

This is about performing the following comparison precisely : CrossProduct(P - P0, P1 - P0) >, < or == 0 Problem definition Given a set of grid points described by the following equation P(x,...
user avatar
0votes
0answers
24views

How to calculate change in coins in python

I was given a prompt that asks to input any amount of money and print how many of each coin is needed for that amount of money. For example, 2.05 would be 8 quarters and 1 nickel. I thought I had it ...
user avatar
  • 1
0votes
2answers
75views

How to convert the values of all fields in data frame from decimal to integers

We have a data frame of 1.1 Million rows X 4300 Columns. The data frame contains different floating values in different columns , example of one of the field value is 0.567. In order to read the ...
user avatar
0votes
1answer
175views

seaborn scatterplot x/y ticks datatype are switched (float values to int, and vice versa)

I'm using seaborn scatterplot to plot engine 'liter' values (float) vs engine 'cylinder' values (integer). There are three 'cylinder' values- 4, 6, and 8. However the ticks for cylinders on the ...
user avatar
0votes
0answers
46views

Python, compare if a Float is close to an Integer

I'm coding a program to analyse sentiments in Tweets. I want to perform a test where I have a dataset of Tweets like this : label,text 0, blabla 1, blablabla 0, blablablabla where label is ...
user avatar
  • 626
0votes
0answers
20views

Floating Point Arithmetic, Integer Overflow cannot turn to 0 right?

{ double piApprox = 0; /* Save the result in this variable */ double epsilon = 0.0001; int i = 0; /* Write the amount of iterations needed in this variable */ double lim = 0; /* ...
user avatar
0votes
2answers
126views

How do I check if a string can be converted to a float or integer value without using try/except?

I have an assignment for my first year programming class in which one of the parts is to convert a string to an integer or float value. However, if the string is not convertible it should pass a value ...
user avatar
0votes
1answer
26views

Rounding issue when finding integers inside the interval with float bounds

I have a code which does the following. In some loop, it solves quadratic inequality (ax^2 + bx + c <= 0, a > 0) and finds integer numbers between the roots (using my own function integer_inside)...
user avatar
0votes
1answer
102views

Int to Float conversion Python to C++

I have a function written in Python that works perfectly for what I need(it wasn't written by me). I need to convert it to C++ so that it provides the same outcome. I know that it saves that float ...
user avatar
0votes
1answer
403views

csv importing latitude column as float need it to be numeric

After importing a csv file, i plot it using streamlit. The issue is that the column type imported for the lat/long is are float. How do I transform this float into a readable format? I have tried a ...
user avatar
  • 1
0votes
1answer
413views

Constrain numpy to automatically convert integers to floating-point numbers (python 3.7)

I have just made the following mistake: a = np.array([0,3,2, 1]) a[0] = .001 I was expecting 0 to be replaced by .001 (and the dtype of my numpy array to automatically switch from int to float). ...
user avatar
0votes
1answer
537views

'float' object has no attribute 'item' when trying to map on series

When I try to convert float64 to float of a single value, it works fine - import pandas as pd a=pd.DataFrame() a['Num']=['1','2','3','4'] a def float(x): return x.item() float(a['Num'].astype('...
user avatar
0votes
1answer
31views

Strange issues summing ints and floats

Can someone please explain this to me? I was writing a def (program) to convert text into numbers and wanted to ensure if it was just ints, the representation was ints and if floats, floats. If a ...
user avatar
0votes
0answers
58views

Python lossy conversion from float to int

I am trying to figure out a way to write 21*(10^21) in Python. I've tried two approaches. The first one is simply by doing the following: >>> print(21*(10**21)) 21000000000000000000000 This ...
user avatar
0votes
0answers
52views

Strange float to int conversion with Visual Studio 2010

Let us say I have float val = 99999.9; When I do this: int val2 = val*100; val2 is equal to 9999989 in Visual Studio 2010. However, if I do the same with other compilers (like GCC for example), ...
user avatar
0votes
3answers
717views

Conversion from float (native float or numpy.float64) to integer not working

I have a dataframe thats loaded with floats and NaNs. I need to convert all the decimals/floats to integers. I checked that all types are numpy.float64 but my conversion to integer does not work. This ...
user avatar
0votes
0answers
109views

TypeError: unsupported operand type(s) for +: 'float' and 'Time'

I'm trying to get this to work, it seems like the problem is when I try to add an hour and a decimal representing time (ex. .75 equating to 45min). I think I need to add something to the init() ...
user avatar
0votes
0answers
445views

Check if byte string represents float or int

I have some byte strings and I don't know if they are integers or floats. Lets create some example data: import numpy as np arr_int = np.array([17, int(1e10), 34567]) arr_float = np.array([17.17,...
user avatar
  • 4,026
0votes
1answer
37views

Need help converting string or int to float

So I have been stuck on this one for a while and could use some help. I have been trying to fix this code and I keep getting an error about invalid syntax. So here is the code I need help with need to ...
user avatar
0votes
0answers
77views

Floating point exception with big numbers and inaccurate results when changing integers to longs

I was given this problem which gives you 2 integers n and m, n representing the number of figures of the second number, and the second number is a binary number. For example: n= 2 m= 11 ...
user avatar
0votes
0answers
361views

How to convert 64FC1 float numbers to "bgr8" uint to publish in ROS?

I need to publish an image after sobel operator, however ROS message does not support float numbers. So how can I publish edge detection message? pub = rospy.Publisher('detector', Image, queue_size=...
user avatar
0votes
2answers
529views

Float is not converting to integer pandas

I used this code to convert my float numbers into an integer, however, it does not work. Here are all step I gone through so far: Step 1: I converted timestamp1 and timestamp2 to datetime in order ...
user avatar
  • 311
0votes
1answer
166views

Excel: How to find closest number in table, many times

Excel Need to find nearest float in a table, for each integer 0..99 https://www.excel-easy.com/examples/closest-match.html explains a great technique for finding the CLOSEST number from an array to a ...
user avatar
0votes
0answers
202views

How to recast float to integer for selected column numbers in Hive?

A number of columns containing what appeared to be 0/1 integer values in my Hive table are rewritten as 0.0 or 1.0 float values after pulling the table into a Python data frame. Therefore what I ...
user avatar
  • 724
0votes
2answers
406views

How to find out the size of a float in PHP?

I'm using PHP 7.2.5(installed using the latest version of XAMPP) on my machine that runs on Windows 10 Home Single Language 64-bit operating system. As per my knowledge, in PHP, the sizes of an ...
user avatar
0votes
0answers
789views

QString to double long float and long long int

Is it possible to convert the part before the decimal point to long long int and the part after the decimal point to long double float? Example: QString "1101.110"; and I would like to change that ...
user avatar
  • 39
0votes
1answer
21views

Calculation of integer and a floating number

Im trying to calculate an integer and a floating number. Sounds like something easy right? However when I execute the following code: <?php $decimals = 2; $dec_point = ','; $thousands_sep = '.'; ...
user avatar
0votes
0answers
35views

Packing integer as floats, finding original ints

We are packing two 12 bits integers into three 8 bits RGB colors to convey values to a GPU. The process goes like this: Two 16 bits integers are generated (U and V) They are decimated to two 12 ...
user avatar
  • 713

15 30 50 per page