logo
down
shadow

How to multiply sequence by non-int of type 'float'?


How to multiply sequence by non-int of type 'float'?

By : Pam Serfass
Date : November 21 2020, 07:38 AM
it fixes the issue Multiplying python lists by an integer gives you a multiple of the list.
code :
>>> a = [1]
>>> a * 3
[1,1,1]
>>> import numpy as np
>>> a = [[1,1],[1,1]]
>>> a = np.array(a)
>>> a * 0.1
array([[ 0.1,  0.1],
   [ 0.1,  0.1]])


Share : facebook icon twitter icon
can't multiply sequence by non-int of type float?

can't multiply sequence by non-int of type float?


By : master_dude
Date : March 29 2020, 07:55 AM
around this issue I've been asked to write a simulator, the end goal being to see how much ink ends up on a cylinder at the end of a chain of maybe 15 or so rollers. I'm currently trying to set-up a dictionary which defines the rollers. From this i wanted to write a function which will take user input, 'roller_diameter', find the ratio of the given diameter to a fixed diameter and convert this into an integer number of 'segments'. I'm not a programmer (i'm learning Python[2.7] using internet resources) and am struggling with the TypeError: can't multipy sequence by non-int type 'float' I'm sure this is a trivial issue and I have looked at the related answers but have been unable to understand what specifically I'm doing wrong...Any suggestions would be greatly appreciated, here's the code (with only a few 'rollers'), please don't laugh... , In this line:
code :
R['segments'] = int(round(rollers[3]['segments']*roller_diameter/plate_diameter))  
TypeError: can't multiply sequence by non-int of type 'float'
rollers[3] = ['top_seg': 0, 'roller_diameter': [], 'segments': [], 'material': Rubber, 'direction': CW, 'ink': []}  
R = rollers[i]  
    R = rollers[i]  
NameError: name 'i' is not defined
def roller_data():  
    global roller_diameter  
    print i
    roller_diameter = float(raw_input("Enter the roller diameter" + str(i) + ': '))
def read_diameter(i):
    return float(raw_input("Enter the roller diameter # {}: ".format(i)))
rollers[i]['roller_diameter'] = read_diameter(i)
TypeError: can't multiply sequence by non-int of type 'float' even if already parsed with float()

TypeError: can't multiply sequence by non-int of type 'float' even if already parsed with float()


By : Yøung Jøseph
Date : March 29 2020, 07:55 AM
it helps some times You are interpolating into the string first, then multiplying the result:
code :
>>> y = 2.5
>>> "Is %f pounds\n" % y*2.205
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't multiply sequence by non-int of type 'float'
>>> "Is %f pounds\n" % (y*2.205)
'Is 5.512500 pounds\n'
print "Is %f kilos\n" % (y/2.205)
print "Is {:f} pounds\n".format(y * 2.205)
print "Is {:f} kilos\n".format(y / 2.205)
Converted to Float and Int, TypeError: can't multiply sequence by non-int of type 'float' Python 2.7

Converted to Float and Int, TypeError: can't multiply sequence by non-int of type 'float' Python 2.7


By : Alferd Jhorden
Date : March 29 2020, 07:55 AM
I hope this helps you . I am trying to open a CSV file, iterate over its row's and convert the final part of row to a new number created by multiplying the existing value with a floating point number. , In your code, neither of
code :
    if isinstance(row[8], float):
        row[8] = float(row[8])
    if isinstance(row[8], int):
        row[8] = int(row[8])
Cant multiply sequence by non-int of type 'float'

Cant multiply sequence by non-int of type 'float'


By : pedro
Date : March 29 2020, 07:55 AM
To fix this issue raw_input() returns a string. You can't multiply a string with a number, so you need to convert the number string to an actual number format first, for instance with the float() function:
code :
number = raw_input()
answercms = float(number) * inches
>>> type(number)
<type 'str'>
>>> type(float(number))
<type 'float'>
TypeError: can't multiply sequence by non-int of type 'float' - after converting to float

TypeError: can't multiply sequence by non-int of type 'float' - after converting to float


By : Kervin Yap Bardilas
Date : March 29 2020, 07:55 AM
To fix the issue you can do From your code I assume that you want entry_validation to return a float, but it is actually returning the string you provide when calling it.
For example, in:
code :
entry_exam1 = entry_validation ('Exam 1')
def entry_validation (assignment) :
    entry = -1

    while entry == -1:
        entry = input ('What was your final score for ' + assignment + '? ')

        if entry == '':
            entry = -1
            print ('ERROR: You cannot leave this field blank. Please try again.')

        else:
            # Let's handle possible exceptions when the input cannot be converted
            try:
                entry = float (entry)
                if entry < 0 or entry > 100:
                     entry = -1
                     print ('ERROR: You score must be between 0 and 100. Please try again.')
                else:
                     return entry
            except ValueError:
                entry = -1
                print("ERROR: Must be a float")
Related Posts Related Posts :
  • Database is not updated in Celery task with Flask and SQLAlchemy
  • Shapely intersections vs shapely relationships - inexact?
  • How to extract a percentage column from a periodic column and the sum of the column?
  • Zombie ssh process using python subprocess.Popen
  • Python regex to capture a comma-delimited list of items
  • joining string and long in python
  • Value Error in python numpy
  • Check if any character of a string is uppercase Python
  • TensorFlow - why doesn't this sofmax regression learn anything?
  • Python Anaconda Proxy Setup via .condarc file on Windows
  • Creating django objects from emails
  • Get spotify currently playing track
  • Select multiple columns and remove values according to a list
  • Python - How to Subtract a Variable By 1 Every Second?
  • Tkinter unable to alloc 71867 bytes
  • How to add Variable to JSON Python Django
  • CSRF token missing or invalid Django
  • Python: writing to a text file
  • Extracting multiple rows from pandas dataframe and converting to columns
  • Pinging a remote PC with Flask, causing server to block
  • Making a fractal graph using a 2D array?
  • Replacing a word in a list with a value from a dict
  • Savefig as eps yields a non-usable eps
  • Crispy-forms InlineRadios don't show my model state
  • Getting Title of a text
  • Python with numpy: How to delete an element from each row of a 2-D array according to a specific index
  • Sending and Receive data from a web page - Selenium
  • KeyError with Pyro4
  • Python module error
  • Python :: Attribute in superclass not available in inheriting subclass
  • Why does greater than and unequal operators work even though only less than and equal operator has been overloaded
  • Input length mismatch scikit
  • Print String in decreasing length
  • Overloading the [] operator in python class to refer to a numpy.array data member
  • Sympy - altering the range of the y axis for a plot
  • How do I programmatically list a DLL's dependencies in C++ or Python?
  • How do I lock window resizing in a Python matplotlib window?
  • Word boundary RegEx search using PyMongo
  • Iterating over a string by only changing one element in the string
  • classification of data where attribute values are strings
  • Validate user input using regular expressions
  • Synchronizing and Resampling two timeseries with non-uniform millisecond intraday data
  • determing the number of sentences, words and letters in a text file
  • Deploying impure Python packages to AWS
  • Navigating between multiple Tkinter GUI frames
  • Python - Do I need to remove instances from a dictionary?
  • How can I get the edited values corresponding to the keys of a dictionary in views.py POST method, passed as a context v
  • differentiate between python function and class function
  • From array create tuples on if condition python
  • Looping over a text file list with python
  • Monitoring a real-time data stream with a flask web-app
  • Bad quality after multiple fade effect with pydub
  • delete rows in numpy array in python
  • What are the possible numpy value format strings?
  • Conditional Selecting of child elements in pdfquery
  • Python: split string by closing bracket and write in new line
  • SyntaxWarning: import * only allowed at module level
  • theano ~ use an index matrix and embeddings matrix to produce a 3D tensor?
  • Django background infinite loop process management
  • How can I use Pandas or Numpy to infer a datatype from a list of values?
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co