Skip to content
murmot

Results for “python numpy array example program for loop of string in java code site:discuss.python.org”

  • discuss.python.org

    An interesting pytype experiment, and a possible extension to strings

    Anyway, numpy arrays are very much iterables – unlike strings, they are used as iterables, very, very often. And indeedAnd here is a little experimental code: from collections.abc import Iterable. def it_of_str(names: Iterable[str]): for i, name in enumerate(names): print(f"name {i}: {name}").

  • discuss.python.org

    Loops, arrays, dictionaries -- oh my - Python Help ...

    Oct 12, 2022 · Is there a way to carry out this set of instructions using a list or dictionary? Or what would your approach be to make the code more efficient? Thx! Do you mean: instead of using np.array? You can certainly do all of this with list s - semanticly your 2x3 np.array can be done with nested list s. But I wouldn’t. numpy (a) has a huge suite of nice math functions for bulk computation, which ...

  • discuss.python.org

    Include `math.sign` - Page 16 - Ideas - Discussions on Python.org

    Preserves the sign of a 0 for Python’s float types (as it appears numpy will be changing to do too). Can you link this again? I can’t find any reference for that. The Array API defines sign here. Sign of zero is very clearly zero for at least the numpy floating types.

  • discuss.python.org

    Numpy array2string write to file - unwanted string split

    Jul 28, 2025 · I loop through my numpy matrix row by row, I convert each row to a string and write to a file, it looks like each string is split into two in the output instead of all being on the same text line: A shortened version of…

  • discuss.python.org

    Setting random NaN in multidimensional numpy array - Python Help...

    I am trying to generate a 4D numpy array that contains a random number of “nan”. I am following a methodology that I have found in this page (How to randomly insert NaN in a matrix with NumPy in Python ? - GeeksforGeeks), concretely “method 2”, that consists in creating a mask.

  • discuss.python.org

    For Loop in Python - Python Help - Discussions on Python.org

    Sep 7, 2023 · Pardon if I have been posting series of questions. Newbie Python learner here, and am going through PCEP materials, and having some questions along the way… Thank you in advance for the help. In these two codes, I confused why the answer is such: Code 1: my_list = [0,1,2,3] x = 1 for elem in my_list: x *= elem print (x) Answer: [0] Code 2: my_list = [0,1,2,3] x = 1 for elem in my_list: new ...

  • discuss.python.org

    Safer logging methods for f-strings and new-style formatting

    (I was advised to move this discussion from the Python bug tracker to here) Logging f-strings is quite popular, but is potentially unsafe with the current logging methods. There are different ways to solve this problem – while keeping new-style formatting.

  • discuss.python.org

    Loop in list and find the vowels for each string - Python ...

    Feb 15, 2023 · Python Tutorials – Real Python Learn Python online: Python tutorials for developers of all skill levels, Python books and courses, Python news, code examples, articles, and more. You’ll find a huge amount of free content as well as the paid-for content.

  • discuss.python.org

    Choice of complex buffer protocol format intentional break with PEP?

    But numpy arrays aren’t Python array.arrays, and for all I know heavy numpy users (which I’m not) may well not expect them to work ...Anyway, Tim’s example of numpy.array([1j], dtype="Zd")not being understood by NumPy can be changed in NumPy if “numpy people” wish it.

  • discuss.python.org

    For Loops assignment - Python Help - Discussions on Python.org

    Sep 15, 2021 · Hi I have to create a simple For Loop but i’m having trouble knowing where to start, this is the program I have to create Create a new program called Lab3A2 that will ask the user to enter an integer 2. The program should use a for loop to: a. Add all the numbers between 1 and the input number. b. Count all the numbers between 1 and the input number. 3. After the loop has completed ...