Skip to main content

All Questions

Tagged with
2 votes
2 answers
63 views

Printing matrices in Python in customized format

I have many matrices such as a below generated in a Python program and need to output them in a specific form. import numpy as np a = np.array([[1/10000009, 2, 3], [3, 4/3000897, 5]]) print(a) This ...
xiaohuamao's user avatar
0 votes
1 answer
59 views

Output formatted 2D text with different number of columns and wrapping in Python

I need to print a 2D array such as a = [[100.0, 200.0, 300.0, 400.0, 500.0, 600.0], [700.0, 800.0, 900.0, 1000.0, 1100.0, 1200.0], [1300.0, 1400.0, 1500.0, 1600.0, 1700.0, 1800.0]] to a ...
MathX's user avatar
  • 134
0 votes
1 answer
66 views

How to format two different size arrays together in a table in python

I am new to python so this could be a silly question. I am trying to format two arrays in an easy to read table. I am hoping to get a table that looks like this Position Time [1 2 3] [100] [3 4 5]...
AlmostAcademic's user avatar
0 votes
2 answers
126 views

How can I convert several NumPy arrays with ints to a NumPy array with formatted strings?

I have three arrays of the same length containing integers: years, months and days. I want to create a (NumPy) array of the same length, containing formatted strings like '(-)yyyy-mm-dd' using the ...
AstroFloyd's user avatar
2 votes
1 answer
444 views

removing scientific notation ONLY for the zero values when printing a numpy array?

Right now my array prints like this: [[ 1.5531e-01 -4.6594e-02 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00] [-4.6594e-02 1.5531e-01 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00] [ 0.0000e+...
ivy's user avatar
  • 37
2 votes
1 answer
3k views

How to sum all the pixels of a PIL image?

i'm doing a project that involves getting every pixel from an image than averaging it out, i'm having some problems here's the code for i in range(0, 3): for j in range(0, 3): img = Image....
Artur's user avatar
  • 23
0 votes
1 answer
35 views

Removing the nan portions of a numpy array Python

I am trying to remove the nan portion of the numpy array how would I be able to do that? Array=np.array([ nan nan nan nan nan nan ...
ege Selcuk's user avatar
-2 votes
1 answer
73 views

C++ & Python : Formating items of an array and removing duplicates from it

I was translating a code from Python to C++ (of which i'm not a frequent user by far, understanding only a little more than just synthax) and got stuck at a point, where i need to format the b array ...
Alan's user avatar
  • 9
1 vote
1 answer
728 views

Print hex game board contents properly

Recently I've been working on a hex board game https://en.wikipedia.org/wiki/Hex_(board_game) project that I found in Python. However due to my rusty coding skills I'm having real trouble figuring out ...
Tatami's user avatar
  • 45
0 votes
1 answer
94 views

How to reshape a numpy data table?

I'm pretty new to python and I have a task to "reshape" some data in a .txt file. The simplified format of the original data looks like this: A 1 x A 2 y A 3 z B 1 q B 2 ...
a Ljeonjko's user avatar
0 votes
1 answer
47 views

Conditional list Python

I am opening all the files present in zip, then converting the string to List and thereafter, breaking the list into 5 elements from each line. My code: with zipfile.ZipFile(dummy.zip, 'r') as mz: ...
Ashish Bansal's user avatar
0 votes
1 answer
854 views

I'm trying to output the already formatted contents of a CSV file into a text channel, but when I do so it's in unordered rows. How can I fix it?

I'm very new to coding, so this kind of thing is still new to me. import csv import discord from discord.ext import commands f = open('discounts.csv') csv_f = csv.reader(f) token = '####' client = ...
gabriel p's user avatar
0 votes
2 answers
69 views

Python: pull out elements of given array in certain order

I have an array of arrays with names, addresses, cities, states, and postal codes. Is there a way I can collectively use the elements and display the information in the format of Name, Address, City, ...
userh16xx0's user avatar
0 votes
1 answer
46 views

How can I format a numpy array to be displayed without excessive 0s without losing its alignment?

I'm trying to display a numpy array that represents a matrix with big numbers in a compact manner without losing the alignment of columns and rows. My code is as follows: EA = 1.8e8 EI = 1.8e7 L = 3 ...
Alejandro's user avatar
0 votes
2 answers
43 views

Format "n" and "k" with brackets in python but its not doing what I would like

if __name__ == "__main__": d = len(sys.argv)>3 n = int(sys.argv[1]) k = int(sys.argv[2]) A = [] for i in range(n): A.append(i) if d: print("[{0} {1}]".format(n,k)) val = combinations(A, k) ...
user avatar

15 30 50 per page